tags:

views:

51

answers:

3

What's the best way to modify web.configs (and other XML based configurations)? I'm needing to automatically apply certain settings based off environment.

+1  A: 

If you mean programatically, there are classes that allow you to do so, such as WebConfigurationManager and ConfigurationManager.

JP Alioto
A: 

You can do this in your build scripts as well. Both Nant and MSBuild have a notion of Xml Peek and Poke.

Generally I'm against the idea of programattically editing the web.config (it will cause your site to reload).

Chris Brandsma
+2  A: 

I usually store my environmental configurations in their own folder with individual config files and reference this with the file attribute of the appsettings tag in the main web.config

  /config/dev.config 
          systest.config
          uat.config
          prod.config

  <appsettings file="config/dev.config">

This means we can deploy all our configs and just switch one value to change environments. The only draw back is this breaks some config editors.

Dave Anderson