dragonfly dragonfly - 2 months ago 8
ASP.NET (C#) Question

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

is it possible to transform following web config appSettings file:

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


into something like this:

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


So, I need to remove one setting with developmentModeUserId key + I need to replace value for key developmentMode.

Thanks

Joe Joe
Answer

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 http://msdn.microsoft.com/en-us/library/dd465326(VS.100).aspx for more info.

Comments