2015-07-12 86 views
4

有没有办法让NuGet包转换配置转换文件?例如,当我想让我的NuGet包编辑web.config文件时,我创建了一个web.config.install.xdt文件。但是如果我想让我的NuGet包编辑web.config.debug文件呢?NuGet包转换配置转换文件

我试着制作一个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的命名空间,但是这并没有帮助)

+0

相关:http://stackoverflow.com/q/30945716/38368 –

+0

我已将[问题](http://blog.nuget.org/20130920/how-to-use-nugets-xdt-feature -examples-and-facts.html)关于这个在nuget博客。 –

回答

1

虽然这也许不是最好的答案,但它确实把工作为我做的当我发现自己在这种情况下:

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

https://docs.nuget.org/create/Transforming-Configuration-Files-Using-dotTransform-Files.md

这似乎运作良好,只要确保适当的xmlns属性是在.transform文件。

例如,如果你想改变目前看起来像这样你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" /> 

通过添加下列网址.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> 

只要确保将其添加到.nu spec文件,因此在打包时会被拾取。