Usually Web.config Transformation is being done during a deployment of dotnet application to various server during deployment time. Here Teamcity is a CI server thus deployment can be done done using WebDAV or Octopus Deploy and integration with Teamcity. Octopus Deploy has in build integration with Teamcity and Web.config Transformation feature.
However, Sometimes you would like to do Web.config Transformation using teamcity as well thus this article might help you understand a scnario.
Before using Web.config Transformation in Temacity, Lets understand a Web.config Transformation basics first using following url.
Now let me give you some more background about Web.config Transformation.
Web.config files typically include settings that have to be different depending on which environment the application is running in. For example, you might have to make changes such as the following when you deploy a Web.config file to a destination server:
- Change a database connection string to point to the production database.
- Disable debugging in the production environment.
- Remove sensitive information such as connection strings, such as if you provide a package to a community site.
To manually manage changes to a Web.config file, you can do the following:
- Edit the Web.config file on the destination server each time the project is deployed.
- Maintain separate versions of the Web.config file for each environment (perhaps in separate folders or using distinctive names), and copy only the version that is appropriate to the destination environment when you deploy.
- Create XSLT files to transform the Web.config and apply the transforms when the application is deployed.
You may read more about this at
Now, There are following methods in which you may call Web.config Transformation using TeamCity
- .NET CLI (dotnet)
- .NET Process Runner
- Command Line
- NuGet Installer
- Visual Studio (sln)
- Visual Studio Tests
Condition and Checklist to verify for web.config transformation to work on build server
Condition 1 – The MSBuild script should be like this
MSBuild.exe PATH_TO_PROJ.csproj /p:DeployOnBuild=true /p:PublishProfile=PUBLISH_TARGET /p:Configuration=Release
Still needed to specify the Configuration as Debug or Release (even though this appears to be an attribute of the publish target.)
Condition 2 – Needed parameters in Teammcity:
system.PublishProfile – set to the value of your PublishProfile (such as Release)
system.DeployOnBuild – set to true
When this is done TeamCity will automatically pass these parameters to your Visual Studio build step and transformation now works.
Method 1 – csproj file changes
If you add the following xml to the bottom of the .csproj file for your web application, you’ll ensure that the config transformation occurs before every build:
Method 2 – csproj file changes
Method 3 – Apply a web.config transform within a Teamcity Build Step
One thing that seems to work (not sure if its the best way) is to add a before/after build event on the csproj file for the website e.g.
Source Reference –
Change value or transform in app.config within TeamCity
- Using PowerShell script
- Using XDT
- File Content Replacer build feature
- Nuget Package “SlowCheetah”
You may find a stackoverflow link for here –
Automatic Deployment From TeamCity Using WebDeploy
Perform web.config transforms on build using MSBuild
How to inject Teamcity’s build parameters into web.config
Using a MSBuild Script in TeamCity
Web.config Transformation Using TeamCity
Running Unit Tests With TeamCity
- How to configure Elastic filebeat 8.3 with Elasticseach? - August 11, 2022
- How to Configure IP Network with ‘nmtui’ Tool - August 11, 2022
- Istio Tutorials: How to install & configure istio?￼ - August 11, 2022