views:

69

answers:

2

Hello everyone,

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?

thanks in advance, George

+1  A: 

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!

anthares
Thanks. Two more questions, 1. the connection string defined in Web.Debug.Config has higher priority than web.config (i.e. will overwrite the value defined in web.config)? 2. In runtime, for example, IIS 7.0, it will use web.config together with Web.Debug.Config (do we need to deploy both config files to IIS)? Or just use web.config?
George2
It depends only what build configuration you have used. You can check these links: http://stackoverflow.com/questions/2791236/what-is-the-web-debug-config-and-web-release-config-file-for http://blogs.msdn.com/b/webdevtools/archive/2009/05/04/web-deployment-web-config-transformation.aspx You have to deploy only the Web.config file. VIsual Studio have taken the correct version and replaced it in your build for you.
anthares
IIS will use "Web.config" only, none of the others will apply. I think you're right on your first question, but someone should confirm.
Alex
There is no "higher priority" the Web.config file is replaced with one of the Web.*.config files in your solution.
anthares
Thanks anthares, you mean either web.config or Web.Debug.Config or Web.Debug.Release will be used, and no content merge operations?
George2
That's correct.
anthares
Thanks Alex, my confusion is either web.config or Web.Debug.Config or Web.Debug.Release will be used, and no content merge operations?
George2
There is no merge operation, one of the files is used as exact copy and is renamed to web.config. Also you can add your onw schemes with proper configurations, for example Web.Test.Config for you test build configuration.
anthares
Another confusion is I find on top of web.debug.config, there is an item called, configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform, what does it mean?
George2
As it is described in the links I provided you, Visual Studio uses transformations to generate you config fille. That's why it's included this namespace. Check out the links for detailed explanation.
anthares
During publish -> Web Deployment, how to select which web.config to use?
George2
These comments are slightly misleading. The web.<x>.configs are not used to replace the web.config, they are used to transform the base web.config. For example, if you have a web.config and a web.release.config that is blank ... you will NOT end up with a blank web.config in the deployed solution. The .debug and .release configs apply special transforms to convert information from the core web.config to environmentally specific values, using the transforms you specify. This is what the namespace declaration at the top is doing.
Taylor
Thanks, question answered!
George2
+1  A: 

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

citronas
Thanks. Two more questions, 1. the connection string defined in Web.Debug.Config has higher priority than web.config (i.e. will overwrite the value defined in web.config)? 2. In runtime, for example, IIS 7.0, it will use web.config together with Web.Debug.Config (do we need to deploy both config files to IIS)? Or just use web.config?
George2
For web deployment, I think you mean when we select "Publish" for the WCF project? If so, from the Publish dialog and if I select WebDeploy as Publish Method, I can not see any options to use Web.Debug.Config or Web.Debug.Release. Any comments?
George2
Another confusion is I find on top of web.debug.config, there is an item called, configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform, what does it mean?
George2
Which settings overrides which has something to do which web.config transforms. To override settings, like have defaultsettings and specific for production, you need to add a specific xmlattribute to the nodes. that is called config transforms, or something like this. The setting you selected in the dropdown will be the one that will replace the default settings, if you added the previous mentioned attribute
citronas
During publish -> Web Deployment, how to select which web.config to use?
George2
You can select the build settings in a dropdown next to the 'run debug' button. If not, you may need to add that toolbar first or you are using the express version of visual studio
citronas