Web.Config Transformation XPath

时间:2012-03-07 11:46:11

标签: web-config

我已经对这里和谷歌(等)的类似帖子进行了常规检查,但无济于事。

基本上我有一个使用Web.Config转换的Visual Studio 2010 MVC3解决方案,并且在大多数情况下它们工作得很好。但是,我有一些单元测试绑定,我想删除它们,因为它们的XML位置,它们有点棘手。

以下是缩减版:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
                <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.HostAdapters.ASPNETAdapter" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                <codeBase version="10.0.0.0" href="file:///C:/Program%20Files/Microsoft%20Visual%20Studio%2010.0/Common7/IDE/PrivateAssemblies/Microsoft.VisualStudio.QualityTools.HostAdapters.ASPNETAdapter.DLL" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.Common" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                <codeBase version="10.0.0.0" href="file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.QualityTools.Common/10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.QualityTools.Common.dll" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.ExecutionCommon" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                <codeBase version="10.0.0.0" href="file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.QualityTools.ExecutionCommon/10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.QualityTools.ExecutionCommon.dll" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.Resource" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                <codeBase version="10.0.0.0" href="file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.QualityTools.Resource/10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.QualityTools.Resource.dll" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="AjaxMin" publicKeyToken="21ef50ce11b5d80f" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-4.46.4422.26284" newVersion="4.46.4422.26284" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

基本上我想删除包含名为“Microsoft.VisualStudio”的子节点的节点。

到目前为止,我可以在转换Web中使用一些冗长的语法来清空节点.Config:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.HostAdapters.ASPNETAdapter" xdt:Transform="Remove" xdt:Locator="Match(name)" />
                <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.Common" xdt:Transform="Remove" xdt:Locator="Match(name)" />
                <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.ExecutionCommon" xdt:Transform="Remove" xdt:Locator="Match(name)" />
                <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.Resource" xdt:Transform="Remove" xdt:Locator="Match(name)" />
                <codeBase version="10.0.0.0" xdt:Transform="RemoveAll" xdt:Locator="Match(version)" />
            </dependentAssembly>
            <dependentAssembly xdt:Locator="XPath(//runtime/*/*[not(node())])" xdt:Transform="RemoveAll" />
        </assemblyBinding>
    </runtime>
</configuration>

这种工作但给了我空的节点,我不想要。

有什么想法吗?

干杯!

1 个答案:

答案 0 :(得分:3)

这就是我删除不需要的dependentAssembly引用的方法,不确定它是否是最好的方法,但它对我有用:

在Web.config中

,为生产不需要的所有dependentAssembly条目添加一个名称,我选择使用“QualityTools”。

 <dependentAssembly name="QualityTools">
    <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.HostAdapters.ASPNETAdapter" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <codeBase version="10.0.0.0" href="file:///C:/Program%20Files/Microsoft%20Visual%20Studio%2010.0/Common7/IDE/PrivateAssemblies/Microsoft.VisualStudio.QualityTools.HostAdapters.ASPNETAdapter.DLL" />
  </dependentAssembly>
    <dependentAssembly name="QualityTools">
    <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.Common" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <codeBase version="10.0.0.0" href="file:///C:/Windows/assembly/GAC_MSIL/Microsoft.VisualStudio.QualityTools.Common/10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.QualityTools.Common.dll" />
  </dependentAssembly>
    <dependentAssembly name="QualityTools">
    <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.ExecutionCommon" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <codeBase version="10.0.0.0" href="file:///C:/Windows/assembly/GAC_MSIL/Microsoft.VisualStudio.QualityTools.ExecutionCommon/10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.QualityTools.ExecutionCommon.dll" />
  </dependentAssembly>
    <dependentAssembly name="QualityTools">
    <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.Resource" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <codeBase version="10.0.0.0" href="file:///C:/Windows/assembly/GAC_MSIL/Microsoft.VisualStudio.QualityTools.Resource/10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.QualityTools.Resource.dll" />
  </dependentAssembly>

在转换文件中,添加转换以删除名为“QualityTools”

的所有条目
 <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
   <dependentAssembly name="QualityTools" xdt:Locator="Match(name)" xdt:Transform="RemoveAll" />
</assemblyBinding>

请注意,Transform是RemoveAll,用于删除具有该名称的所有条目。