首页 文章

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

提问于
浏览
4

我正在开发一个项目,其中包括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 .

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

Update to clarify why it's not a duplicate question of 3158928

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

1 回答

  • 0

    您可以在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>
    

相关问题