[thelist] VS2005 Web Site project: managing configuration settings

Jason Handby jason.handby at corestar.co.uk
Thu May 10 07:00:38 CDT 2007

Hi all,

I have a Web Site project which needs different configuration settings
in its live server environment than it does in its test environment. (A
database connection string, a path where some XML files are located, and
so on.)

In VS2003 / ASP.NET 1.1, I was using custom build configurations that
#define'd an appropriate constant, and was then using that constant to
decide what key to use with ConfigurationSettings.AppSettings[] when
retrieving settings from the web.config, etc.  So for example I could
have all my database connection strings in my web.config:

		<add key="TEST_connectionString" value="blah"/>
		<add key="LIVE_connectionString" value="different

This was great because:

 - I could have one web.config with all my settings in it -- no worries
about the deployment process overwriting with the wrong version;
 - All I had to remember to do was to change the build configuration
before I rebuilt and copied my site to the live server;
 - The connection string could be changed on the live and running site
just by editing the web.config.

In VS2005 this approach seems not to work due to the changes in the way
that web projects are built -- it seems that you can't have multiple
custom build configurations for Web Site projects.

So, my question is, what's the "right" way to achieve this using VS2005
/ ASP.NET 2? The fact that my existing method doesn't work any more
suggests I was doing this the "wrong" way before :-)

Should I be putting my configuration information in machine.config on my
servers? This doesn't seem  right to me. Should I have a different
web.config for each destination? It's only a matter of time before I
accidentally overwrite one of them without noticing. Should I turn my
Web Site project into a Web Application project, and carry on doing it
the way I was before?

Any ideas and advice would be welcomed :-)


More information about the thelist mailing list