How to change the value of attribute in appSettings section with Web.config transformation

dragonfly picture dragonfly · Jun 14, 2012 · Viewed 107.9k times · Source

Is it possible to transform the following Web.config appSettings file:

<appSettings>
    <add key="developmentModeUserId" value="00297022" />
    <add key="developmentMode" value="true" />
    /* other settings here that should stay */
</appSettings>

into something like this:

<appSettings>
    <add key="developmentMode" value="false" />
    /* other settings here that should stay */
</appSettings>

So, I need to remove the key developmentModeUserId, and I need to replace the value for the key developmentMode.

Answer

Joe picture Joe · Jun 14, 2012

You want something like:

<appSettings>
  <add key="developmentModeUserId" xdt:Transform="Remove" xdt:Locator="Match(key)"/>
  <add key="developmentMode" value="false" xdt:Transform="SetAttributes"
          xdt:Locator="Match(key)"/>
</appSettings>

See Also: Web.config Transformation Syntax for Web Application Project Deployment