Search code examples
slowcheetahxdt-transform

XML transformation not working


I have installed the SlowCheetah extension and Nuget Package into my Console App Project. I have used the context menu to add a UAT build configuration and updated a test setting to check that the value is being transformed.

Unfortunately its not, when I try to Preview the Transform via the Context Menu its just showing me the non transformed App.Config.

What steps can I check to see why this extension is not working?

In the main App Config I have specified an appSetting.

<appSettings>
    <add key="TomTestTransform" value="LOCAL" />
</appSettings>

In the App.UAT.config I overwrite it

<appSettings>
    <add key="TomTestTransform" value="UAT" />
</appSettings>

When I preview the Transform, or build and check the configuration output, its always using the non transformed version. The setting equals LOCAL.


Solution

  • You need to use xdt: attributes to match and adapt the elements, like so:

    <?xml version="1.0" encoding="utf-8" ?>
    <!-- For more information on using transformations 
     see the web.comfig examples at http://go.microsoft.com/fwlink/?LinkId=214134. -->
    <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
      <appSettings>
        <add key="TomTestTransform"
             value="UAT"
             xdt:Transform="Replace"
             xdt:Locator="Match(key)" />
      </appSettings>
    </configuration>
    

    With xdt:Locator="Match(key)" you are telling the processor to match the add element based on the key attribute, and apply xdt:Transform="Replace" logic on the whole (located) element.

    There is a msdn entry available on possible XML transformations, which is also applicable for SlowCheetah transformations, as they are based on the same "technology".

    Additionally, the extension overview has also some good documentation in it!