Web.config转换 - 缺少的手册 [英] Web.config transforms - the missing manual

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

问题描述

您可以阅读web.config转换文档此处和<一个href =http://vishaljoshi.blogspot.com/2009/03/web-deployment-webconfig-transformation_23.html>那里,但有两个没有人似乎讨论的白象: p>

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


  1. 如何在 Condition 中执行变量替换XPath transform,and ...

  2. 可以有定位器有意义的嵌套在变换

  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>

假设我要完全删除 dependentAssembly 节点及其子项,与xpath // runtime / assemblyBinding / dependentAssembly [assemblyIdentity@name='System.Web.Mvc]]匹配。为了做到这一点,我可能会想这样:

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>

很明显,我弥补了语法 @ name = $ name 基于 xpath变量概念,但此示例演示了为什么我想要该功能。这是否支持?我应该如何调整我的语法以利用这一点?我可以放一个字符串字面值,但是我只是想知道这是否可行。

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>

注意变形父节点,并且定位器在叶节点上。以上是否合法?这个想法是仅删除具有内部定位器匹配的 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?

推荐答案

p> @ 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转换 - 缺少的手册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆