2015-07-12 85 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文件,因此在打包時會被拾取。