XDT transformation removes wrong entry

283 views Asked by At

I am using this site to test my XDT transformations before using in NuGet. When i have this config

<?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>

And use this transform:

<?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>

The result is this output:

<?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>

I do not understand why the entry ApplicationInsightsWebTracking is removed and not ErrorLog. I got the same results when using this transformation in a NuGet package (when removing the package). How to change the transformation in a working one?

1

There are 1 answers

0
har07 On BEST ANSWER

You need to explicitly tell XDT to match by name attribute as well, by using xdt:Locator="Match()", otherwise only the element location/path will be considered for matching (that's why the first add element got removed initially) :

<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>