[thelist] VS2005 Web Site project: managing configuration settings

Jason Handby jason.handby at corestar.co.uk
Fri May 11 02:48:25 CDT 2007

I wrote:
> 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:
> 	<appSettings>
> 		<add key="TEST_connectionString" value="blah"/>
> 		<add key="LIVE_connectionString" value="different
> blah"/>
> 	</appSettings>


> 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 :-)

OK, so I've made some progress in answering my own question!

For web projects with multiple build configurations, the solution seems
to be either to convert from a Web Site project to a Web Application
Project, and carry on as before, or to add a Web Deployment project
which will allow you to modify sections of the web.config file depending
on the selected build configuration.

As I said in my previous post, I wanted to do this the "right" way, and
reverting back to an old model seemed like a retrograde step. So I went
for the Web Deployment project option. Unfortunately I cannot get it to
work. I keep getting an error message about not having specified an
output path, despite the fact that I clearly have. From my googling it
would seem that quite a few people get this error message but that there
is no clear consensus on what causes it or what the solution is.

Great :-)

So I guess I now have to convert my project to a Web Application
Project, so I can build it the way I was building it in VS2003.

Unless anyone has any other ideas or suggestions?


More information about the thelist mailing list