MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Web.config Transformation Using TeamCity explained

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
https://docs.microsoft.com/en-us/previous-versions/dd394698(v=vs.100)?redirectedfrom=MSDN#webconfig_transformation

Now, There are following methods in which you may call Web.config Transformation using TeamCity

  • .NET CLI (dotnet)
  • .NET Process Runner
  • Command Line
  • MSBuild
  • MSpec
  • NuGet Installer
  • PowerShell
  • 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:

TeamCity system properties with DeployOnBuild true and PublishProfile set to FileSystemRelease for config transformation
TeamCity MSBuild build step Publish API with DeployOnBuild, PublishProfile and PublishUrl command line parameters

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 –

  • https://stackoverflow.com/questions/10506308/web-config-file-transform-from-command-line/10506476#10506476
  • https://stackoverflow.com/questions/39569396/apply-a-web-config-transform-within-a-teamcity-build-step

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 –

  • https://stackoverflow.com/questions/37201731/change-value-in-app-config-within-teamcity
  • https://github.com/devopsschool-sample-projects/teamcity-config-transform
  • https://stackoverflow.com/questions/37201731/change-value-in-app-config-within-teamcity

Automatic Deployment From TeamCity Using WebDeploy

  • http://www.mikevalenty.com/automatic-deployment-from-teamcity-using-webdeploy/

Perform web.config transforms on build using MSBuild

  • http://danielsaidi.com/blog/2013/04/04/perform-webconfig-transforms-on-build

How to inject Teamcity’s build parameters into web.config

  • https://teamcity-support.jetbrains.com/hc/en-us/community/posts/206833975-How-to-inject-Teamcity-s-build-parameters-into-web-config

Using a MSBuild Script in TeamCity

  • https://cgeers.wordpress.com/2011/06/04/using-a-msbuild-script-in-teamcity/

Web.config Transformation Using TeamCity

  • https://cgeers.wordpress.com/2011/08/21/web-config-transformation-using-teamcity/

Running Unit Tests With TeamCity

  • https://cgeers.wordpress.com/2011/05/28/running-unit-tests-with-teamcity/

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Continuous Integration Training Blueprint for .NET Teams (MSBuild, TeamCity, NUnit, NCover, FxCop, Web Deploy)

This revised guide converts an older CI course announcement into a practical training blueprint for build and release teams. It maps each tool to the pipeline, shows a workflow diagram, and includes realistic command-line examples for labs.

Read More

Team Foundation Build 2010: Architecture, Build Definitions, and Migration from TFS 2008

Team Foundation Build 2010 introduced a controller/agent build architecture, richer build definitions, and gated check-in workflows for TFS teams. This revised guide turns the original topic list into a practical reference for setup, customization, and migration planning.

Read More

Host Your Own NuGet Feed: Local Source vs NuGet.Server vs NuGetGallery

Learn how to host a private NuGet feed using three practical approaches: a local folder source, NuGet.Server, and NuGetGallery. This revised guide includes setup steps, command examples, and a workflow diagram to help you choose the right model.

Read More

Publish NuGet Packages to NuGet.org: CLI Steps, Workflow, and CI Example

Learn how to publish a NuGet package to NuGet.org using either nuget.exe or the dotnet CLI. This revised guide includes a workflow diagram, command comparison, and a CI-friendly example.

Read More

How to Create NuGet Packages with nuget.exe (Assembly, .nuspec, and .csproj Methods)

Learn three practical ways to build NuGet packages using nuget.exe: from an existing assembly, from a convention-based folder layout, or directly from a Visual Studio project. This guide includes commands, folder conventions, token behavior, and common pitfalls.

Read More

.NET Build and Release Training: Curriculum, Toolchain, Workflow, and Enrollment

A structured, engineer-friendly rewrite of the original .NET Build and Release course page. Review objectives, tool coverage, CI/CD workflow, prerequisites, fees, and key links in one place.

Read More