Web.config Conversion - Missing Guide

You can read the web.config documentation conversion here and there , but there are two white elephants that no one is discussing:

  • How do you perform variable substitution in a Condition or XPath transform and ...
  • Can a Locator Be Capable Inside a Transform ?

Let me give you an example that would benefit from any of these options. Suppose I have this:

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

Suppose I want to completely erase the dependentAssembly node and its children that correspond to xpath //runtime/assemblyBinding/dependentAssembly[ assemblyIdentity@name ='System.Web.Mvc'] . For this, I might need something like this:

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

Well, obviously, I compiled the syntax @name=$name based on xpath variable variables , but this example demonstrates why I want this function. Is it supported? How do I customize my syntax to take advantage of this? I could insert a string literal, but I just want to know if this is possible.

Another way that I can try to remove the dependentAssembly node is as follows:

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

Notice that the Transform is on the parent node, and the locator is on the node sheet. Is it legal? The idea is to remove only the dependantAssembly node, which has an internal locator match.

These two approaches to the side, how would you like to remove the dependantAssembly targeting and all its child nodes?

+6
source share
3 answers

The @Thommy solution worked for me, and the @LifeintheGrid solution used the actual assemblies that I wanted to remove, so I combined them and simplified to get:

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

The problem is the namespace attribute in the assemblyBinding tag.

Removing an AspNetHelper link for me works as follows:

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

This code worked for me. I moved the conversion to the dependent cell node.

 <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> 
+3
source

Source: https://habr.com/ru/post/927222/


All Articles