Darcy Casselman
Darcy Casselman

Reputation: 2644

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?

Upvotes: 0

Views: 1539

Answers (2)

Darcy Casselman
Darcy Casselman

Reputation: 2644

Another option may be to upgrade the web site to a web application.

That could be a lot of work to make the transition now, but the ability to have configurations may help tip the scales if you're deciding to go with a web site or web application.

Upvotes: 0

JB King
JB King

Reputation: 11910

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.

Upvotes: 1

Related Questions