asp.netweb-configconfig-transformation

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


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.


Solution

  • 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>