19

I'm used to use web deployment projects. Currently I am developing a new web application with VS2010 and want to try to get along with the new web.config principle and deployment issues.

How can I replace a simple setting like

<applicationSettings>
  <NAMESPACE>
   <setting name="Testenvironment" serializeAs="String">
    <value>True</value>
   </setting>
  </NAMESPACE>
</applicationSettings>

I want to have this setting to be set to True in Debug, and false in Release. How must the entries in the Web.Debug.config and Web.Release.Config look like?

And by the way: Is there some documentation about the new web.config issue? Can't seem to google for the correct keywords.

citronas
  • 19,035
  • 27
  • 96
  • 164

5 Answers5

45

The best way would be to do the following:

<applicationSettings> 
  <NAMESPACE> 
   <setting name="Testenvironment" serializeAs="String"  xdt:Transform="Replace" xdt:Locator="Match(name)"> 
    <value>True</value> 
   </setting> 
  </NAMESPACE> 
</applicationSettings> 

Rather than Zubeyir suggestion as this one will only replace the specifed setting rather than replacing the WHOLE of the applicationSettings section.

Jonathan Stanton
  • 2,531
  • 1
  • 28
  • 35
  • 1
    yep to be more specific Jonathan Stanton suggestion is the best answer because the answer Zubeyir suggested will replace all applicationSettings and when you update your debug version by adding new settings and you forgot to update the release version as well every things well be replaced with release verion of webconfig – Kiarash Feb 12 '13 at 01:44
14

You could also use this way; for the prod environment for example.

<applicationSettings xdt:Transform="Replace">
  <NAMESPACE> 
   <setting name="Testenvironment" serializeAs="String"> 
    <value>False</value> 
   </setting> 
  </NAMESPACE> 
</applicationSettings> 

Regards.

Zubeyir
  • 331
  • 2
  • 8
  • Because I still had this to figure out: A transformation does just apply when publishing a website/application, not when building/compiling it. – Kai Hartmann Feb 04 '15 at 07:34
3

You should copy this setting to both web config files - Web.Debug.config and Web.Release.config and put the transformation attributes xdt:Transform="SetAttributes" xdt:Locator="Match(name)".

You can see this video tutorial - http://chriskoenig.net/index.php/2010/04/08/how-do-i-web-config-transformations-in-vs2010/

Hope that helps.

bluish
  • 26,356
  • 27
  • 122
  • 180
Thea
  • 7,879
  • 6
  • 28
  • 40
  • 4
    Sorry this isn't the right answer. "SetAttributes" just sets the attributes. If you want to change the value tag you need "Replace"! – Dirk Brockhaus Aug 13 '10 at 07:29
1

Here is a link with lots of samples on this theme: http://msdn.microsoft.com/en-us/library/dd465326.aspx.

But there seems to be a problem especially with Web.config transformations and applicationSettings: All answers on this query using xdt-Transform=“Replace” have the problem that they introduce additional white space into the deployed Web.config because of XML formatting. This leads to faulty behavior if you consume the resulting settings. There seems to be no solution. Here is my unanswered question on this problem: VS 2010 configuration transformation produces unwanted white space during deployment.

Community
  • 1
  • 1
Dirk Brockhaus
  • 4,922
  • 3
  • 38
  • 47
1

You might also have a look at How to use web.config transforms to replace appSettings and connectionStrings

citronas
  • 19,035
  • 27
  • 96
  • 164