转换 Web 配置以进行发布



我的 Web 配置中有以下 XML,在发布模式下,我需要根据其子项的名称属性删除 dependentAssembly 部分:assemblyIdentity。我在这里尝试了答案:xdt 转换定位器与子节点内容匹配但没有运气。我的web.config是这样的:

    <?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" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.Resource" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <codeBase version="10.0.0.0" href="file:///c:/Program%20Files%20(x86)/Microsoft%20Visual%20Studio%2010.0/Common7/IDE/PrivateAssemblies/Microsoft.VisualStudio.QualityTools.HostAdapters.ASPNETAdapter.DLL" />
      </dependentAssembly>
  </assemblyBinding>
  </runtime>
</configuration>

我已经在我的web.release.config中尝试了以下内容,以根据子元素选择要删除的第二个dependentAssembly元素,但没有成功。

    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" >
          <dependentAssembly>
<!-- Attempt 1 -->
            <assemblyIdentity  xdt:Transform="RemoveAll"
             xdt:Locator="Condition(@name='Microsoft.VisualStudio.QualityTools.Resource')"/>
          </dependentAssembly>
        </assemblyBinding>
<!-- Attempt 2 -->
 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly xdt:Transform="Remove"
       xdt:Locator="Condition(assemblyIdentity/@name='Microsoft.VisualStudio.QualityTools.Resource')">
        </dependentAssembly>
     </assemblyBinding>
      </runtime>

这段代码对我有用。

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly xdt:Transform="Replace" xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='System.Web.Mvc')">
      <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
      <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0"/>
    </dependentAssembly>      
  </assemblyBinding>
</runtime>

所有功劳都归功于@Thommy对这篇文章的堆栈溢出答案。

最新更新