views:

58

answers:

3

I have different settings for production and development in my web.config file. I am constantly changing the file manually when moving between the environments. Is there a way to automatically have visual studio use the correct settings for the environment that I publish to? Or should I have 2 versions of the web.config file?

+1  A: 

I maintain separate versions for each environment. Further I have, configured my deploy tool to pick up right version.

Saar
What deploy tool do you use?
Joe
it's in house developed tool.
Saar
A: 

Are the instances on different web servers? If so, consider moving the settings from the web.config to the machine.config and the values will stay with the machine.

http://forums.asp.net/p/1117776/1736929.aspx

Otherwise, use separate web.configs.

asp316
I am on a shared server and don't have access to the path for the machine.config
Joe
A: 

My approach has been to have multiple config files. I put all environment agnostic stuff (i.e. doesn't matter if dev, staging, or production) in the web.config file. Anything that is specific to the environment (i.e. database connection info, logging, debug settings, etc.) I put into a local.config file specific to the environment. You can then include the local.config settings in the web.config using configSource (http://weblogs.asp.net/fmarguerie/archive/2007/04/26/using-configsource-to-split-configuration-files.aspx)

Web.config can then be checked into source control. Don't check in the local.config files - that forces you to deploy the correct one in your deploy scripts.

Brian Frantz