Reputation: 397
Is there a way to make a NuGet package transform a config transform file? For example, when I want my NuGet package to edit a web.config
file, I create a web.config.install.xdt
file. But what if I want my NuGet package to edit a web.config.debug
file?
I tried making a web.config.debug.install.xdt
file, but ran into one issue: I cannnot get the transformation to insert attributes that are themselves attributes of xdt transformation. Something like:
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:xdt1="http://schemas.microsoft.com/XML-Document-Transform">
<system.serviceModel >
<client xdt1:Transform="Insert">
<endpoint address="http://blah.blah" binding="basicHttpBinding" contract="Test.Contract"
name="TestWs" xdt:Transform="Replace" xdt:Locator="Match(name)"/>
</client>
</system.serviceModel>
</configuration>
(I tried changing the namespace of xdt, but that didn't help either.)
Upvotes: 4
Views: 2095
Reputation: 11
Although this isn't perhaps the best answer, it did get the job done for me when I found myself in this situation:
Use the "old" method of doing transforms, not the xdt way.
https://docs.nuget.org/create/Transforming-Configuration-Files-Using-dotTransform-Files.md
This seems to work well, just make sure the appropriate xmlns attribute is in the .transform file.
For example, if you wanted to transform your web.qa.config file that currently looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="Tier" value="qa" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
</appSettings>
</configuration>
You could add an element:
<add key="RedirectUri" value="yourRedirectUriForQA" xdt:Transform="Replace" />
By adding the following web.qa.config.transform file to your Nuget package:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="RedirectUri" value="yourRedirectUriForQA" xdt:Transform="Replace" />
</appSettings>
</configuration>
Just make sure also to add it to the .nuspec file so it gets picked up when packaged.
Upvotes: 1