views:

136

answers:

3

I have an ASP.Net web site (ASPX and ASMX pages) with a single web.config file. We have a development version and a production version. Over time, the web.config files for development and production have diverged substantially.

What is the best practice for keeping both versions of web.config in source control (we use Tortoise SVN but I don't think that matters)? It seems like I could add the production web.config file with a name like "web.config.prod", and then when we turnover all the files we would just add the step of deleting the existing web.config and renaming web.config.prod to web.config.

This seems hackish, although I'm sure it would work. Is there not some mechanism for dealing with this built in to Visual Studio? It seems like this would be a common issue, but I haven't found any questions (with answers) about this.

+1  A: 

Visual Studio 2010 adds a new feature called XDT Transforms, which automatically combines multiple Web.config files for different configurations.

However, VS2008 does not include any such feature.

SLaks
VS 2008 doesn't have this? We're stuck on 2008.
MusiGenesis
+2  A: 

We use the exact method you describe, it works great, for example we have:

  • web.config (for local development)
  • web.Dev.config (build server, builds on check-in)
  • web.QC.config (testing environment)
  • web.Prod.config (production)

The build script for each environment just deletes the web.config and renames the appropriate one in it's place. Doing this way allows you to easily source control all of them and very quickly do a diff and see what may be different between environments. Updating a config value across the board is much easier as well...the next time it's pushed to that environment, it'll get the new config.

Nick Craver
+4  A: 

I use nant for my builds. On the SVN I have a web.config.template that contains parameters that are expanded using a properties file. Each environment has its own properties file with different values.

So in short, I don't have the web.config on the SVN, but a template instead.

Something like this

http://www.cptloadtest.com/2007/09/22/Managing-Multiple-Environment-Configurations-Through-NAnt.aspx

NAnt: http://nant.sourceforge.net/

Claudio Redi