2010-12-16 66 views
8

我正在使用可通過VS2010使用的web.config轉換。在這種情況下,我想知道在轉換過程中是否可以將元素與另一個元素「包圍」。這裏有一個例子:Web.config轉換 - 圍繞元素

默認的web.config包含:

<configuration> 
    <system.web> 
    .... 
    </system.web> 
</configuration> 

我轉換文件應包含

<configuration> 
    <location inheritInChildApplications="false"> 
    <system.web> 
    ... 
    </system.web> 
    </location> 
</configuration> 

所以基本上我想「包裝」與位置system.web元素元件。我唯一的想法就是做一個轉換,以便我之前和之後一樣插入:

<location inheritInChildApplications="false" 
      xdt:Transform="InsertBefore(/configuration/system.web)"> 
</location xdt:Transform="InsertAfter(/configuration/system.web)"> 

但收盤位置元素是不是按照VS有效的XML(我猜是因爲變換屬性)。只需在system.web之前插入一個自我關閉的位置元素也無濟於事,因爲生成的system.web仍未被「包圍」。

回答

2

目前,它是不可能做到這一點使用的web.config改造,但如果你寫了一個自定義的轉換確實應該是可行的......還有正在制定關於如何編寫自定義一個文檔更新改造,但它是尚未走出現在......

我會盡快,因爲它是可以張貼...

+0

有沒有想過這個?我目前正在研究這種確切的情況。 – 2016-06-14 11:14:01

2

如果您在webconfig添加一個空位置標籤,你想它是將有沒有效果。與結束標記

<location xdt:Locator="XPath(some xpath expression)" 
      inheritChildApplications="false" 
      xdt:Transform="SetAttributes(inheritChildApplications)"> 

也和所有:

然後可以把這個在你轉換文件在同一位置爲另外一個。