2012-10-09 24 views
6

Możesz przeczytać web.config przekształca dokumentację here i there, ale istnieją dwa białe-słonie, że nikt nie wydaje się, aby omówić:Web.config przekształca - brakująca instrukcja

  1. W jaki sposób wykonać podstawienia zmiennej w Condition lub XPath przekształcania i ...
  2. czy Locator być sensownie zagnieżdżone wewnątrz Transform?

Pozwolę sobie podać przykład, który skorzystałby z jednej z tych opcji. Załóżmy, że mam to:

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

Przypuśćmy, że chcesz całkowicie usunąć węzeł dependentAssembly, a jej dzieci, które dopasowuje XPath //runtime/assemblyBinding/dependentAssembly[[email protected]='System.Web.Mvc']. Aby to zrobić, ja mogę chcieć coś takiego:

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

No oczywiście wymyśliłem składnię @name=$name oparciu o xpath variable concepts, ale ten przykład pokazuje, dlaczego chciałbym tej funkcji. Czy to jest obsługiwane? Jak muszę dostosować moją składnię, aby z tego skorzystać? Mogę wpisać literał smyczkowy, ale chcę tylko wiedzieć, czy to możliwe.

Innym sposobem mógłbym spróbować usunąć węzeł dependentAssembly, jest z tym:

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

Zawiadomienie Transform jest na węźle grand-dominującej, a lokator jest węzeł liścia. Czy powyższe jest uzasadnione? Pomysł polega na usunięciu tylko węzła dependantAssembly z wewnętrznym dopasowaniem lokalizatora.

Pomijając te dwa sposoby, w jaki sposób usunąć adresowanie dependantAssembly i wszystkie jego węzły podrzędne?

Odpowiedz

6

@ rozwiązanie Thommy pracował dla mnie, a @ rozwiązanie LifeintheGrid za wykorzystane rzeczywiste zespoły chciałem usunąć, więc połączyliśmy dwa i uproszczone, aby uzyskać :

<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

Ten kod zakończył się dla mnie. Przeniosłem transformację do węzła 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

Problemem jest atrybut namespace w tagu assemblyBinding.

Usuwanie prace odniesienia AspNetHelper mi z tym:

<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

To zadziałało i powinno być oznaczone jako odpowiedź na to pytanie. – sebastiaan