在同一解决方案中引用 2 个不同版本的 log4net [英] Referencing 2 different versions of log4net in the same solution

查看:15
本文介绍了在同一解决方案中引用 2 个不同版本的 log4net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用引用 log4net 1.2.10.0 的 NHibernate 2.1.2.400.在同一个项目中,我也使用了简单的accounting SDK,遗憾的是它仍然使用log4net 1.2.9.0.

所以如果我引用 log4net 1.2.10.0,我可以让 NHibernate 工作,但 simpleSDK 不起作用.反之亦然...

我猜大多数问题来自 log4net 更改了其程序集密钥这一事实.我尝试使用绑定重定向但没有成功:2 个 DLL 没有相同的键.

我正在考虑重新编译 NHibernate 以使用 log4net 1.2.9.0,但这似乎是错误的做法,我的感觉是,Simply Accounting 不会很快更新他们的 SDK 以使用 log4net 1.2.10.0.

处理这个问题的最佳方法是什么?有没有可能解决?

解决方案

我通过使用此对类似问题的回答找到了解决方案问题

您在项目中为每个 log4net 版本创建了 2 个文件夹.通过将文件添加到解决方案(不添加引用),将每个 log4net.dll 放在其相应的文件夹中.您可以将复制到输出目录属性设置为始终复制,以便在构建时自动复制到输出文件夹.

然后通过添加如下内容来修改 app.config 文件:

<预><代码><配置><运行时><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><从属程序集><assemblyIdentity name="log4net" publicKeyToken="681549d62126b7b8"/><codeBase version="1.2.9.0" href="log4netv1.2.9.0log4net.dll"/></dependentAssembly><从属程序集><assemblyIdentity name="log4net" publicKeyToken="1b44e1d426115821"/><codeBase version="1.2.10.0" href="log4netv1.2.10.0log4net.dll"/></dependentAssembly><从属程序集><assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a"/><codeBase version="1.2.11.0" href="log4net.dll"/></dependentAssembly></assemblyBinding></运行时></配置>

您可以使用 sn -T [assemblyName] 获取程序集的公钥令牌

I'm using NHibernate 2.1.2.400 that is referencing log4net 1.2.10.0. In the same project, I also use the simply accounting SDK, sadly it is still using log4net 1.2.9.0.

So I can get NHibernate to work if I reference log4net 1.2.10.0 but the simplySDK don't work. And vice versa...

I'm guessing most of the problems come from the fact that log4net has changed its assembly key. I tried using a binding redirection without success: the 2 DLLs do not have the same key.

I'm considering recompiling NHibernate to use log4net 1.2.9.0 but it seems like the wrong thing to do and my feeling is that Simply Accounting won't be updating their SDK to use log4net 1.2.10.0 anytime soon.

What is the best way to handle this? Is it possible to resolve at all?

解决方案

I found the solution by using this answer to a similar question

You create 2 folders in your project one for each version of log4net. Place each log4net.dll in its corresponding folder by adding an the file to the solution (not with add reference). You can set the copy to output directory property to copy always so that it is automatically copied to the output folder when you build.

Then you modifiy the app.config file by adding something like this:

<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.0log4net.dll" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="log4net" publicKeyToken="1b44e1d426115821" />
        <codeBase version="1.2.10.0" href="log4netv1.2.10.0log4net.dll" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" />
        <codeBase version="1.2.11.0" href="log4net.dll" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

you can get the public key token of an assembly by using sn -T [assemblyName]

这篇关于在同一解决方案中引用 2 个不同版本的 log4net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆