是否可以在单个项目中引用同一程序集的不同版本? [英] Is it possible to reference different version of the same assembly into a single project?

查看:81
本文介绍了是否可以在单个项目中引用同一程序集的不同版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的解决方案中,我有几个使用Log4Net的项目(1.2和2.5)。

In my solution, I have several projects which use Log4Net (1.2 and 2.5).

然后我有一个项目,我在其中进行所有单元测试(其他项目)。因此,我处于一种情况,根据我的测试/模拟情况,我需要Log4Net 1.2或2.5。

Then I have a project where I do all the unit testing (of the other projects). So I'm in a situation where depending on what I test/mock I would need Log4Net 1.2 or 2.5.

我读到您可以在其中支持单个组件的不同版本一个应用程序(使用代码库等),但是甚至可以在项目中支持单个程序集的不同版本吗?如果是,怎么办?

I read you could support different version of a single assembly in an application (using codebase etc.) but is it even possible to support different version of a single assembly into a project? If so, how?

EDIt:

这里很小(2个类,2个方法,2个构造函数)显示我的问题的项目:

Here's a tiny (2 classes, 2 methods, 2 constructors) project showing my issue:

https://srv-file1.gofile.io/download/EQFdOs/212.76.254.142/Log4NetMulti.zip

(我希望链接有效)

推荐答案

感谢Pikoh的建议,我设法使它起作用。但是,由于它不仅需要使用别名和重命名dll,因此我将写下整个过程。

Thanks to Pikoh's advices I managed to make it work. But since it requires more than just using alias and rename dll, I'll write down the whole process.


  1. 删除项目中的现有引用(例如:log4net.dll)

  2. 添加文件夹到项目中以存储多个dll(例如:/ Libs)

  3. 在其中添加多个dll,并为其赋予唯一的文件名(例如log4net.1.2.10.0.dll,log4net.1.2) .15.0.dll)

  4. 转到这些文件的属性,然后选择 复制:始终复制:如果更新则复制

  5. 向这些文件添加引用

  6. 赋予这些引用唯一的别名(例如: log4net_1_2_10_0,log4net_1_2_15_0)

  7. 在您的代码中,使用 外部别名关键字来使用别名。

  1. Remove the existing reference (ex: log4net.dll) from the project
  2. Add a folder to the project to store the several dll (ex: /Libs)
  3. Add the several dll in it and give them unique file names (like log4net.1.2.10.0.dll, log4net.1.2.15.0.dll)
  4. Go to property on those files and chose "Copy: Always" or "Copy: Copy if newer"
  5. Add references to those files
  6. Give those references unique aliases (ex: log4net_1_2_10_0, log4net_1_2_15_0)
  7. In you code, make use of the aliases, using "extern alias" keywords.

extern alias log4net_1_2_10_0;

using log4net_1_2_10_0.log4net;
using System.Web;
...


  • 添加代码库到您的配置文件。这些应该引用您放入文件夹的dll,以及正确的版本和令牌。

  • Add codebases into your config file. Those should refer to the dll you placed into your folder, with the proper version and token.

    <runtime> 
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" />
          <codeBase version="1.2.15.0" href="Libs/log4net.1.2.15.0.dll"/>
        </dependentAssembly>
        <dependentAssembly>
          <assemblyIdentity name="log4net" publicKeyToken="1b44e1d426115821" />
          <codeBase version="1.2.10.0" href="Libs/log4net.1.2.10.0.dll"/>
        </dependentAssembly>
      </assemblyBinding>
    </runtime>  
    


  • 这篇关于是否可以在单个项目中引用同一程序集的不同版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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