I use the configuration manager and define DEBUG, TEST, RELEASE as compile time constants. For configurations I use Web.config Transformation Syntax for Web Application Project Deployment and would highly recommend using them.
For example:
//web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="MyConnectionString"
connectionString="Data Source=SqlServer\Sql2008;
Initial Catalog=MyDB.Dev;
Integrated Security=SSPI"
providerName="System.Data.SqlClient" />
</connectionStrings>
<add key="SomeAppSetting"
value="DebugValue"/>
</configuration>
Test transformation:
//web.Test.config
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="MyConnectionString"
connectionString="Data Source=SqlServer\Sql2008;
Initial Catalog=MyDB.Test;
Integrated Security=SSPI"
providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes"
xdt:Locator="Match(name)"/>
</connectionStrings>
<add key="SomeAppSetting"
value="TestValue"
xdt:Transform="SetAttributes"
xdt:Locator="Match(key)"/>
</configuration>
When I change my configuration from debug to test and rebuild/deploy my app now uses the transformation update in my web.Test.config
. Extremely useful.
You can build different configurations using the Configuration Manager Dialog Box. At anytime you can right click on the web.config and select Add Config Transformations to have Visual Studio 2010 create the transformation config files automagically.