views:

465

answers:

4

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.

+1  A: 

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.

Teddy
Thanks you very much =)
citronas
I'm glad to help :)
Teddy
Sorry this isn't the right answer. "SetAttributes" just sets the attributes. If you want to change the value tag you need "Replace"!
Dirk
+1  A: 

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
+1  A: 

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
A: 

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:

http://stackoverflow.com/questions/3300210/vs-2010-configuration-transformation-produces-unwanted-white-space-during-deploym

Dirk