Web.config转换 - 缺少手册

时间:2012-10-09 03:11:10

标签: visual-studio-2010 xslt deployment xpath web-config

您可以阅读web.config转换文档herethere,但有两只白象无人似乎在讨论:

  1. 如何在ConditionXPath转换中执行变量替换,以及......
  2. Locator <{1}} <{1}}

    让我举一个可以从这两个选项中受益的例子。假设我有这个:

    Transform

    假设我想要完全删除与xpath <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节点及其子节点。要做到这一点,我可能想要这样的东西:

    //runtime/assemblyBinding/dependentAssembly[assemblyIdentity@name='System.Web.Mvc']

    很明显我基于xpath variable concepts制作了语法<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节点的另一种方法是:

    dependentAssembly

    请注意<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及其所有子节点?

3 个答案:

答案 0 :(得分:7)

问题是assemblyBinding标记上的namespace属性。

删除AspNetHelper参考资料对我有用:

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

答案 1 :(得分:7)

@Thommy的解决方案对我有用,@ LifeintheGrid的解决方案使用了我想删除的实际程序集,因此我将两者结合起来并简化为:

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

答案 2 :(得分:3)

此代码最终为我工作。我将转换移动到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>