unity-containernuget-packagexdt-transform

How can I transform a unity.config file in a nuget package?


I'm trying to transform the contents of a unity.config file at the target of a nuget package. That file looks like this:

<?xml version="1.0"?>
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
  <container>
    <register type="SomeProject.Data.ISecurityManager, SomeProject.Data"
    mapTo="SomeProject.MockSecurityManager, SomeProject.Data" />
  </container>
</unity>

I want to update the value of "mapTo". I'm updating a bunch of stuff in the web.config with the standard web.config.install.xdt, but the key problem here seems to be that the namespace conflicts between the unity namespace and the transform namespace. So when I create an xdt with the following header for transformation:

<unity xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

Nothing in that file matches, because it's looking in a file with the actual root namespace like so:

<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">

I'm starting to lean towards a Powershell script...can anyone make this approach work?


Solution

  • Just try to add two namespaces for unity node to transform config. It looks like this:

    <?xml version="1.0"?>
    <unity xmlns="http://schemas.microsoft.com/practices/2010/unity" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
      <container>
        <register xdt:Transform="Replace" 
                  xdt:Locator="Match(type)"
                  type="SomeProject.Data.ISecurityManager, SomeProject.Data"
                  mapTo="It's my test type)">
        </register>
      </container>
    </unity>
    

    It works fine for me. So let me know if it doesn't work for you.