asp.netvisual-studiovisual-studio-2008configurationbuild-environment

How can I set up different build configurations for ASP.Net web site projects?


According to an earlier question about Visual Studio configurations, there's no way to use Visual Studio's configuration manager to create different configurations for an ASP.net web site project.

For normal projects, we have #if directives that switch certain server or database variables depending on whether we're debugging or in production. This doesn't work for web sites.

For example, in a class (in App_Code) that defines a web site's back-end server connection, there might be a chunk of code like this which overrides production values in the web.config if you want to run a debug server on your local machine:

#if DEBUGLOCAL
           ServerProperties.ServerIP = "localhost";
           ServerProperties.DataContextIP = "localhost";
#endif

This doesn't work, since there's no "Debug Local" configuration for the website, thus no DEBUGLOCAL defined.

Have you found a good way to work around problems like this? Besides (I hope) refactoring everything so all those references live in a class library project?

ETA: Can web deployment projects help here?


Solution

  • Perhaps a Web Deployment project that does some swapping in the web.config may be of some help? Another thought would be to have a connection string in the web.config that pulls various values from a pre-specified database that can exist in each environment to allow for easy changes to the settings without needing to touch any files.