Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change an web.config setting using transformation syntax?

Tags:

I have a value stored in my web.config file that I would like to change when the site is published. I want to change it from TEST to LIVE.

<appSettings>     <add key="RequestMode" value="TEST" />     // other keys here </appSettings> 

Is this possible using web.config transformation syntax? If so, how?

Thanks.

like image 356
dotnetnoob Avatar asked Mar 28 '13 14:03

dotnetnoob


People also ask

What is web Config Transforms?

A Web. config transformation file contains XML markup that specifies how to change the Web. config file when it is deployed. You can specify different changes for specific build configurations and for specific publish profiles.

How do I rename a web config transform?

If you go to Build > Configuration Manager... and select the Active solution configuration drop-down you can add new build names. Afterward you can right-click your web. config and Add Config Transform , which asks no questions and just creates one transform for each build.

Does machine config override web config?

The machine. config file file is at the highest level in the configuration hierarchy while Web. config file is to override the settings from the machine. config file.


1 Answers

Yes this is possible with transformation syntax. This transformation should do the trick:

<?xml version="1.0" encoding="utf-8"?> <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">   <appSettings>     <add key="RequestMode" value="LIVE" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>   </appSettings> </configuration> 
like image 99
Erik Schierboom Avatar answered Sep 23 '22 11:09

Erik Schierboom