2

I have an ASP.NET MVC app with multiple web.config transforms. I am using TeamCity to build and deploy the application using WebDeploy.

I want to be able build and package in Release mode in one TeamCity build. I want a second build to take the package from the first build, run a web.config transform for a specific environment, and deploy to that environment.

I have done this with Octopus Deploy, because it has a feature to run web.config transforms on a given NuGet package.

How can I accomplish this using msbuild and WebDeploy? They seem to tie the web.config transform closely to the process of compiling code. I'd rather not compile code once for each environment.

awright
  • 1,224
  • 1
  • 13
  • 23

3 Answers3

2

It might be possible to use a powershell step as a build step to transform your config for a specific environment. That way you don't need to compile the code in each build configuration for each environment.

There's an example here: Web config transforms outside of msbuild and I've also seen a suggestion to create a 'meta-runner' in Team City which should make it easier to apply this to multiple projects. Working with Meta-Runners

Community
  • 1
  • 1
darth_phoenixx
  • 932
  • 12
  • 23
2

We had this same problem but found the newer Parameterization feature in WebDeploy fits this use case perfectly! ConfigTransforms (and SlowCheetah) use MSBuild and happen at build time. Parameterization is built into WebDeploy and provides transformation of files at deploy time.

Parameterization is more powerful than ConfigTransforms because it supports transformation of any text file type (.txt, .php, .sql, etc) not just xml files.

Basically you create a parameters.xml file that defines how/what you want to transform and then setParameters files for each environment/target thats basically just a dictionary (key/value pairs) for the config changes. We typically name these setParameters.[env].xml.

See the following links for more information:

chief7
  • 14,263
  • 14
  • 47
  • 80
0

I ended up doing this with a TransformXml step in an MSBuild file. Here's the process:

  1. Build the web project with DeployOnBuild=true
  2. Use Powershell to make a copy of the output package for each server
  3. Use Powershell to invoke msbuild using a project file with only a TransformXml target, to run the appropriate transform for each server.

awright
  • 1,224
  • 1
  • 13
  • 23