本文介绍了Web.config 转换 - 缺少的手册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以在此处那里,但有两只白象似乎没人讨论:>

You can read web.config transforms documentation here and there, but there are two white-elephants that nobody seems to discuss:

  1. 如何在 ConditionXPath 转换中执行变量替换,以及...
  2. Locator 可以有意义地嵌套在 Transform 中吗?
  1. How do you perform a variable substitution in a Condition or XPath transform, and...
  2. 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>

假设我想完全删除与 xpath //runtime/assemblyBinding/dependentAssembly[assemblyIdentity@name='System.Web.Mvc' 匹配的 dependentAssembly 节点及其子节点].为此,我可能想要这样的东西:

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>

显然我根据 xpath 变量编写了语法 @name=$name概念,但这个例子说明了为什么我想要这个功能.这是支持的吗?我必须如何调整我的语法以利用这一点?我可以输入字符串文字,但我只想知道这是否可行.

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.

我可能会尝试删除 dependentAssembly 节点的另一种方法是:

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>

注意 Transform 在祖父节点上,定位器在叶节点上.以上合法吗?这个想法是只删除具有内部定位符匹配的 dependantAssembly 节点.

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.

抛开这两种方法,你将如何删除目标 dependantAssembly 及其所有子节点?

These two approaches aside, how would you go about deleting the targeting dependantAssembly and all its child nodes?

推荐答案

@Thommy 的解决方案对我有用,@LifeintheGrid 的解决方案使用了我想要删除的实际程序集,所以我将两者结合并简化得到:

@Thommy's solution worked for me, and @LifeintheGrid's solution used the actual assemblies I wanted to remove, so I combined the two 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>

这篇关于Web.config 转换 - 缺少的手册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 09:07