Search code examples
visual-studio-2010msbuildweb-config

Can web.config transforms be chained?


Let's pretend that we have the following servers [dev, test, production] and that dev and test are very similar in configuration while production is quite different.

If I'm using web.config transforms that means I have to duplicate a lot of settings för Web.dev.config and Web.test.config. It would be very nice if I could use the same transform mechanism for my transforms so that test.config is based on dev.config.

I have thought of two possible approaches, i'm not sure any of them would work:

  • Try to get MSBuild to first transform dev.config and then run test.config against the result when we are running under test configuration
  • trying to get the transform mechanism to work for transformations files. I would somehow run test.config against dev.config and create a temporary file which I then use as as a transformation against Web.config.

Does anyone know if something like this is possible? And if so how would one go about to set it up?


Solution

  • The TransformXml is just an MSBUILD task that is invoked post compile. If you extend/mod your build you can have it run the transform task twice, or allow the normal run against your configurations, then provide a second file and use the task to perform that.

    If you are familiar with msbuild, this is pretty simple. If not, reply/comment, and I'll try to provide examples later today.

    But in the end, yes its possible, as I've had similar need on past projects.