You can read web.config transforms documentation here and there, but there are two white-elephants that nobody seems to discuss:
- How do you perform a variable substitution in a
Condition
or XPath
transform, and...
- Can a
Locator
be meaningfully nested inside a Transform
?
Let me give an example that would benefit from either of those 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 matches the xpath //runtime/assemblyBinding/dependentAssembly[assemblyIdentity@name='System.Web.Mvc']
. To do that, I might want 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 made up the syntax @name=$name
based on xpath variable concepts, but this example demonstrates why I'd want that feature. Is this supported? How must I adjust my syntax to take advantage of this? I could put in a string literal, but I just want to know if this is possible.
Another way I might try to delete the dependentAssembly
node, is with this:
<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 the Transform
is on a grand-parent node, and the locator is on leaf node. Is the above legitimate? The idea is to remove only the dependantAssembly
node that has an internal Locator Match.
These two approaches aside, how would you go about deleting the targeting dependantAssembly
and all its child nodes?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…