1
votes

I am using VSTS 2010 + ASP.Net + C# 4.0 to learn someone else's code for a WCF application. I find besides Web.Config, there are also Web.Debug.config and Web.Release.config. I searched the content of Web.Config, but cannot find any reference to Web.Debug.config and Web.Release.config. However in VSTS 2010 IDE solution explorer, I find there is an arrow pointed from Web.Config to Web.Debug.config and Web.Release.config -- so seems there is reference relationship. It makes me confused.

In all 3 config files, there are identical items with different values, for example, in web.config, there is connection string DBConnectinString defined in this way,

  <connectionStrings>
    <add name="DBConnectinString" connectionString="data Source=10.10.10.123;uid=foo;pwd=foo;database=FOO" providerName="System.Data.SqlClient"/>
  </connectionStrings>

And in Web.Debug.config, there is connection string DBConnectinString defined in almost the same way with different values,

  <connectionStrings>
    <add name="DBConnectinString" connectionString="data Source=10.10.10.124;uid=foo;pwd=foo;database=FOO" providerName="System.Data.SqlClient"/>
  </connectionStrings>

My quesiton is,

  1. what is the relationship between Web.Config and Web.Debug.config/Web.Release.config?
  2. Why define the same item with different values in Web.Config and Web.Debug.config/Web.Release.config?
2

2 Answers

1
votes

This is new feature in Visual studio 2010. It allows you to have diffrent config files for you build configuration schemes. So that, when you build in debug mode it will include the Web.Debug.Config file, the same when you build for release.

This allows you for example to maintain diffrent configs for your database - one for your dev environment and for your live environment.

Hope that helps!

2
votes

You have different config files for different settings. Consider Debug as your local environment settings, like connectionstrings to the testserver, debug variables on, etc. The Release settings would contain settings like the connectionstring for the production server.

In the top bar, next to the run debug should be a drop down, containing all available settings. You can also add some.

This settings are useful for oneclick-deployment like the new WebDeploy with VS2010

Edit:
This link How to use web.config transforms to replace appSettings and connectionStrings? should show you a basic walkthrough about web.config transforms