How do you handle multiple web.config files for multiple environments? How do you handle multiple web.config files for multiple environments? asp.net asp.net

How do you handle multiple web.config files for multiple environments?


Scott Gu had an article on this once. The solution he presented was to use a Pre-build event to copy the correct config into place depending on the build configuration chosen.

I also noticed that there already is a similar question here on SO.


Transforms seem really helpful for this. You can replace certain sections with different rules.

http://msdn.microsoft.com/en-us/library/dd465318(v=vs.100).aspx


The way we've been doing it is to override the AppSettings section:

<appSettings file="../AppSettingsOverride.config">    <add key="key" value="override" />        ...</appSettings>

This only works for the appSettings section and so is only useful to a degree. I'd be very interested in more robust solutions.

Edit Below

Just watched this:http://channel9.msdn.com/shows/10-4/10-4-Episode-10-Making-Web-Deployment-Easier/

VS2010 has config transforms which look pretty awesome, should make multiple configurations a complete breeze.