我正在使用web.config转换来更改生产环境中的链接,但在预览时,转换不会发生..
这是我的代码:
web.Test.config
<configuration>
<appSettings>
<add key ="ELeg" value ="1"/>
</appSettings>
</configuration>
<system.web>
Run Code Online (Sandbox Code Playgroud)
web.Prod.config
<configuration>
<appSettings>
<add key ="ELeg" value="10" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
</appSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
在prod和test envoirment上预览它时,它不会添加appSetting.
有谁知道问题是什么?
UPDATE
这是我的整个测试转换:
<?xml version="1.0" encoding="utf-8"?>
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an attribute "name" that has a value of "MyDB".
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<configuration>
<appSettings>
<add key ="ELeg" value ="1" xdt:Transform="Insert" />
</appSettings>
</configuration>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)
你没有一把钥匙= 10匹配,你有一把钥匙= ELeg;
换句话说,这个(未经测试的)转换应该更好;
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key ="ELeg" value ="10" xdt:Transform="SetAttributes(value)" xdt:Locator="Match(key)"/>
</appSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
变换属性的说明
xdt:Locator="Match(key)" // Find elements with matching `key`.
xdt:Transform="SetAttributes(value)" // Set the `value` attribute on the matches
Run Code Online (Sandbox Code Playgroud)
编辑:如果你想插入它甚至不存在,那么平原xdt:Transform="Insert"就是你想要的;
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key ="ELeg" value ="10" xdt:Transform="Insert" />
</appSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2613 次 |
| 最近记录: |