2012-10-09 41 views
6

你可以閱讀的web.config文件轉換和herethere,但有兩個白色的大象,似乎沒有人討論:Web.config文件轉換 - 失蹤手冊

  1. 你如何執行一個變量替換一個ConditionXPath轉換和...
  2. 一個Locator可以是有意義嵌套在一個Transform

讓我舉一個例子,從這兩個選項中獲益。假設我有這樣的:

<runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
    <dependentAssembly> 
     <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> 
    </dependentAssembly> 
    <dependentAssembly> 
     <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" /> 
    </dependentAssembly> 
    </assemblyBinding> 
</runtime> 

假設我想徹底刪除dependentAssembly節點,和它的孩子們,與XPath //runtime/assemblyBinding/dependentAssembly[[email protected]='System.Web.Mvc']匹配。要做到這一點,我想可能是這樣的:

<runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
    <dependentAssembly> 
     <assemblyIdentity 
      name="System.Web.Mvc" 
      xdt:Remove 
      xdt:Locator="Condition(..[*@name=$name])" 
     /> 
    </dependentAssembly> 
    </assemblyBinding> 
</runtime> 

嗯,顯然我提出了基於xpath variable concepts語法@name=$name,但這個例子說明了爲什麼我會希望該功能。這是否支持?我如何調整語法來利用這個優勢?我可以放入一個字符串文字,但我只想知道這是否可能。

另一種方式我可能會嘗試刪除dependentAssembly節點,是這樣的:

<runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" xdt:Transform="Remove"> 
    <dependentAssembly> 
     <assemblyIdentity name="System.Web.Mvc" xdt:Locator="Match(name)" /> 
    </dependentAssembly> 
    </assemblyBinding> 
</runtime> 

通知的Transform是一個盛大父節點上,而定位爲葉節點上。以上是合法的嗎?這個想法是隻刪除具有內部定位符匹配的dependantAssembly節點。

拋開這兩種方法,你將如何去刪除目標dependantAssembly及其所有子節點?

回答

6

@ Thommy的解決方案爲我和@ LifeintheGrid的解決方案中使用的實際組件我想要刪除,所以我兩者相結合,並簡化獲得:

<runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly xdt:Transform="RemoveAll" 
          xdt:Locator="Condition(starts-with(./_defaultNamespace:assemblyIdentity/@name,'Microsoft.VisualStudio.QualityTools'))"> 
     </dependentAssembly> 
    </assemblyBinding> 
</runtime> 
3

此代碼最終爲我工作。我將轉換移動到了dependentAssembly節點。

<runtime> 
    <assemblyBinding> 
    <!-- ending /dependentAssembly is required or tranforms fail --> 
    <dependentAssembly xdt:Transform="Remove" xdt:Locator="Condition(assemblyIdentity/@name='Microsoft.VisualStudio.QualityTools.HostAdapters.ASPNETAdapter')" ></dependentAssembly> 
    <dependentAssembly xdt:Transform="Remove" xdt:Locator="Condition(assemblyIdentity/@name='Microsoft.VisualStudio.QualityTools.Common')" ></dependentAssembly> 
    <dependentAssembly xdt:Transform="Remove" xdt:Locator="Condition(assemblyIdentity/@name='Microsoft.VisualStudio.QualityTools.ExecutionCommon')"></dependentAssembly> 
    <dependentAssembly xdt:Transform="Remove" xdt:Locator="Condition(assemblyIdentity/@name='Microsoft.VisualStudio.QualityTools.Resource')" ></dependentAssembly> 
    </assemblyBinding> 
</runtime> 
7

問題是assemblyBinding標籤上的名稱空間屬性。

卸下AspNetHelper參考書對我有這樣的:

<runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly xdt:Transform="Remove" 
          xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='Microsoft.VisualStudio.Enterprise.AspNetHelper')"> 
     </dependentAssembly> 
    </assemblyBinding> 
</runtime> 
+0

這工作,應標記爲這個問題的答案。 – sebastiaan