asp.net - 如何在 Web 配置中转换替换 dependentAssembly?

标签 asp.net web-config web-config-transform xdt-transform

因此,当有人将我的 nuget 包添加到他们的代码中时,我尝试替换 dependentAssembly。

我要更改的程序集是:

 <dependentAssembly>
    <assemblyIdentity name="Common.Logging.Core" publicKeyToken="af08829b84f0328e" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
  </dependentAssembly> 

因此,我使用此 xml 文件并从以下位置获取帮助:Web.config transforms - the missing manual

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly xdt:Transform="Replace" xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name:'Common.Logging.Core')">
        <assemblyIdentity name="Common.Logging.Core" publicKeyToken="af08829b84f0328e" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="2.2.0.0" />
    </dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

但我收到错误:对项目中的“web.config”应用转换时发生错误:“blabla”具有无效的限定名称。

注意到,当我将“替换”更改为“删除”时,它会删除完整的 dependentAssembly,但后来不知何故,它再次将相同的 dependentAssembly 添加到 web.config 中。也许是因为 Common.Logging.Core 依赖项是在 web.config 转换后添加的?

也许这就是替换不起作用的原因?

最佳答案

试试这个:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

      <!-- first completely remove the parent element -->
      <dependentAssembly xdt:Transform="RemoveAll"
                         xdt:Locator="Condition(starts-with(./_defaultNamespace:assemblyIdentity/@name,'Microsoft.Diagnostics.Tracing.EventSource'))">
      </dependentAssembly>

      <!-- then add the new block -->
      <dependentAssembly xdt:Transform="Insert">
        <assemblyIdentity name="Microsoft.Diagnostics.Tracing.EventSource" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.1.16.0" newVersion="1.1.16.0 " />
      </dependentAssembly>

    </assemblyBinding>
  </runtime>

关于asp.net - 如何在 Web 配置中转换替换 dependentAssembly?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30911209/

相关文章:

ASP.NET MVC : Using LINQ to XML to render (X)HTML

c# - 在 VS 2012 项目中启用 System.Net.Http

asp.net - Web配置转换为自定义部分

visual-studio-2012 - 转换此节点的正确xdt:Locator参数是什么?

javascript - 使用 asp.net 和 iis 在地理服务器中进行身份验证

javascript - IE11 Edge JavaScript 已弃用和过时的功能

c# - 通过 C# 代码将 appSettings 部分添加到 web.config

asp.net - TicketCompatibilityMode 上的 IIS 配置错误

c# - 如何使用配置转换删除 ConnectionString

ASP.NET MVC - 设置自定义 IIdentity 或 IPrincipal