2

在 NuGet 中使用之前,我正在使用这个站点来测试我的 XDT 转换。当我有这个配置

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <httpModules>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
      <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
  </httpModules>
  </system.web>
</configuration>

并使用此转换:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.web>
    <httpModules>
      <add name="ErrorLog" xdt:Transform="Remove" />      
    </httpModules>
  </system.web>
</configuration>

结果是这个输出:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <httpModules>

      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
      <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
    </httpModules>
  </system.web>
</configuration>

我不明白为什么条目 ApplicationInsightsWebTracking 被删除而不是 ErrorLog。在 NuGet 包中使用此转换时(删除包时),我得到了相同的结果。如何改变工作中的转换?

4

1 回答 1

1

您还需要通过 using 明确告诉 XDT 按name属性进行匹配xdt:Locator="Match()",否则只会考虑匹配元素位置/路径(这就是add最初删除第一个元素的原因):

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.web>
    <httpModules>
      <add name="ErrorLog" xdt:Locator="Match(name)" xdt:Transform="Remove" />      
    </httpModules>
  </system.web>
</configuration>
于 2016-12-23T08:41:48.120 回答