如何使用转换语法更改web.config设置?

dot*_*oob 21 asp.net web-config config-transformation

我有一个存储在我的web.config文件中的值,我想在网站发布时更改.我想将它从TEST更改为LIVE.

<appSettings>
    <add key="RequestMode" value="TEST" />
    // other keys here
</appSettings>
Run Code Online (Sandbox Code Playgroud)

这是否可以使用web.config转换语法?如果是这样,怎么样?

谢谢.

Eri*_*oom 45

是的,这可以通过转换语法实现.这种转变应该可以解决问题:

<?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>
Run Code Online (Sandbox Code Playgroud)