1

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 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

6 Comments

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?
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?
Another confusion is I find on top of web.debug.config, there is an item called, configuration xmlns:xdt="schemas.microsoft.com/XML-Document-Transform, what does it mean?
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
During publish -> Web Deployment, how to select which web.config to use?
|
1

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!

11 Comments

It depends only what build configuration you have used. You can check these links: stackoverflow.com/questions/2791236/… blogs.msdn.com/b/webdevtools/archive/2009/05/04/… You have to deploy only the Web.config file. VIsual Studio have taken the correct version and replaced it in your build for you.
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.
There is no "higher priority" the Web.config file is replaced with one of the Web.*.config files in your solution.
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.
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.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.