NuGet包转换配置转换文件

NuGet包转换配置转换文件,nuget,web.config-transform,xdt-transform,Nuget,Web.config Transform,Xdt Transform,有没有办法将NuGet包转换为配置转换文件?例如,当我希望我的NuGet包编辑web.config文件时,我会创建一个web.config.install.xdt文件。但是,如果我想让我的NuGet包编辑web.config.debug文件,该怎么办 我试图创建一个web.config.debug.install.xdt文件,但遇到了一个问题:我无法通过转换插入属性,而这些属性本身就是xdt转换的属性。比如: <?xml version="1.0" encoding="utf-8" ?&g

有没有办法将NuGet包转换为配置转换文件?例如,当我希望我的NuGet包编辑
web.config
文件时,我会创建一个
web.config.install.xdt
文件。但是,如果我想让我的NuGet包编辑
web.config.debug
文件,该怎么办

我试图创建一个
web.config.debug.install.xdt
文件,但遇到了一个问题:我无法通过转换插入属性,而这些属性本身就是xdt转换的属性。比如:

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


(我尝试更改xdt的名称空间,但也没有帮助。)

虽然这可能不是最好的答案,但当我发现自己处于这种情况时,它确实帮了我的忙:

使用“旧”的转换方法,而不是xdt方式

这似乎很有效,只需确保.transform文件中有适当的xmlns属性

例如,如果要转换当前看起来像这样的web.qa.config文件:

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

您可以添加一个元素:

<add key="RedirectUri" value="yourRedirectUriForQA" xdt:Transform="Replace" />

通过将以下web.qa.config.transform文件添加到Nuget包中:

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

只需确保将其添加到.nuspec文件中,以便在打包时将其提取。

相关:我已在nuget博客上发表了一篇关于此的文章。