我使用一個web.config轉換來改變生產環境中的一個鏈接,但預覽時,轉換不會發生..我的web.config變換不起作用
這裏是我的代碼:
web.Test.config
<configuration>
<appSettings>
<add key ="ELeg" value ="1"/>
</appSettings>
</configuration>
<system.web>
web.Prod.config
<configuration>
<appSettings>
<add key ="ELeg" value="10" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
</appSettings>
</configuration>
當previewi在產品和測試環境中,它不會添加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>
謝謝。但是我意識到問題不在於它顯示爲與測試web.config相同的值。問題是它根本不顯示appSettings。我認爲最好有一個'xdt:Transform =「Insert(value)」'而不是'xdt:Transform =「SetAttributes(value)」'.becase我需要添加appSetting而不是替換舊的(原始web.config中沒有appSetting)我是否正確? –
@ Simon.S添加了一個示例(如果我正確理解您的問題) –
謝謝..我得到錯誤:「源文檔中沒有元素匹配'/ configuration/configuration/appSettings' –