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

dotnetnoob picture dotnetnoob · Mar 28, 2013 · Viewed 21.7k times · Source

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.

Answer

Erik Schierboom picture Erik Schierboom · Mar 28, 2013

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>