微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 如何使用具有不同log4net版本要求的两个不同NuGet包

我正在开发一个项目,其中包括UmbracoCms NuGet包,它在内部使用log4net框架版本1.2.11来执行日志记录.现在我们要添加一个依赖于log4net 1.2.15的包(SharpRaven.Log4Net).只安装第二个NuGet包就会产生异常:

Could not load file or assembly 'log4net,Version=1.2.11.0,Culture=neutral,PublicKeyToken=null' or one of its dependencies. The located assembly's 
manifest deFinition does not match the assembly reference. (Exception from 
HRESULT: 0x80131040)

这显然是因为Umbraco引用了1.2.11版本而我的项目现在引用了1.2.15版本,但我该如何解决这个问题呢?我不能:

>更改任一软件包的版本要求(真的不愿意从源代码构建它们)
>将两个引用添加到我的项目中,因为它们是相同的组件(VS不允许)
>删除1.2.15版本并添加1.2.11版本.这给了我同样的错误,但随后是其他版本号.
>创建一个bindingRedirect,因为所需的log4net versinos没有publicToken.

我没有看到任何其他选项,所以任何帮助将不胜感激.

更新以澄清为什么它不是3158928的重复问题

我想强调的是,这里的问题是NuGet包引用的log4net程序集的PublicKeyToken为null.这里发布的早期问题Referencing 2 different versions of log4net in the same solution有一些很好的答案,但没有这个问题,因此没有回答这个问题.

解决方法

您可以像在此 awnser中一样并排运行log4net版本:

基本上你为每个版本创建一个文件夹,然后在你的配置中绑定它:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="log4net" publicKeyToken="681549d62126b7b8" />
        <codeBase version="1.2.9.0" href="log4netv1.2.9.0\log4net.dll" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="log4net" publicKeyToken="1b44e1d426115821" />
        <codeBase version="1.2.10.0" href="log4netv1.2.10.0\log4net.dll" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" />
        <codeBase version="1.2.11.0" href="log4net.dll" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐