尽管名称定位器,Web.config转换删除了第一个设置

时间:2016-08-01 16:58:12

标签: xml visual-studio-2015 web-config web.config-transform

我有一个严重行为不当的Web.config转换。我的web.config看起来像这样:

<configuration>
  <configSections>  </configSections>
  <appSettings>  </appSettings>
  <connectionStrings>  </connectionStrings>
  <system.web>  </system.web>
  <runtime>  </runtime>
  <system.webServer>  </system.webServer>
  <entityFramework>  </entityFramework>
  <elmah>  </elmah>
  <applicationSettings>
    <MySite.Properties.Settings>
      <setting name="CommandTimeout" serializeAs="String">
        <value>180</value>
      </setting>
      <setting name="LoginServerUrl" serializeAs="String">
        <value>mydevsite.com</value>
      </setting>
    </MySite.Properties.Settings>
  </applicationSettings>
</configuration>

当我认为我应该能够得到它时:

<MySite.Properties.Settings>
  <setting name="LoginServerUrl" serializeAs="String" xdt:Transform="Replace" xdt:Locator="Match(name)">
    <value>myqasite.com</value>
  </setting>
</MySite.Properties.Settings>

但是当我这样做时,它取代了第一个设置(命令超时)并将第二个设置留在那里,这样我就有2个loginserverurl设置而没有命令超时!

我可以将mydevsite.com转换为myqasite.com的唯一方法是创建一个执行此操作的转换:

<?xml version="1.0" encoding="utf-8"?>

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
    <customErrors mode="Off" xdt:Transform="Replace">
      <error statusCode="404" redirect="~/Error/Error404"/>
    </customErrors>
  </system.web>
  <applicationSettings>
    <MySite.Properties.Settings>
      <setting name="LoginServerUrl" xdt:Transform="Remove" xdt:Locator="Match(name)"/>
      <setting name="CommandTimeout" xdt:Transform="Insert" serializeAs="String">
        <value>180</value>
      </setting>
      <setting name="LoginServerUrl" serializeAs="String" xdt:Transform="Replace" xdt:Locator="Match(name)">
        <value>myqasite.com</value>
      </setting>
    </MySite.Properties.Settings>
  </applicationSettings>
</configuration>

我在这里做错了吗?

1 个答案:

答案 0 :(得分:0)

使用您的配置(在App.config文件中),以下(在App.Debug.config文件中)对我来说非常有效:

我唯一需要添加的是<applicationSettings>标记来包装<MySite.Properties.Settings>

<?xml version="1.0"?>
<!-- For more information on using app.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <applicationSettings>
    <MySite.Properties.Settings>
      <setting name="LoginServerUrl" serializeAs="String" xdt:Transform="Replace" xdt:Locator="Match(name)">
        <value>myqasite.com</value>
      </setting>
    </MySite.Properties.Settings>
  </applicationSettings>
</configuration>

我正在使用&#34; Configuration Transformation&#34; VS Extension为我创建嵌套文件:

project file structure