简体   繁体   English

是否可以将同一装配的不同版本引用到单个项目中?

[英]Is it possible to reference different version of the same assembly into a single project?

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. 所以我的情况取决于我测试/模拟我需要Log4Net 1.2或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: 编辑:

Here's a tiny (2 classes, 2 methods, 2 constructors) project showing my issue: 这是一个很小的(2个类,2个方法,2个构造函数)项目,显示了我的问题:

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

(I hope the link work) (我希望链接工作)

Thanks to Pikoh's advices I managed to make it work. 感谢Pikoh的建议,我设法让它发挥作用。 But since it requires more than just using alias and rename dll, I'll write down the whole process. 但是因为它需要的不仅仅是使用别名并重命名dll,我会写下整个过程。

  1. Remove the existing reference (ex: log4net.dll) from the project 从项目中删除 现有引用 (例如:log4net.dll)
  2. Add a folder to the project to store the several dll (ex: /Libs) 在项目中添加一个文件夹来存储几个dll(例如:/ 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) 在其中添加几个dll并为它们提供唯一的文件名 (如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) 为这些引用提供唯一别名 (例如: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 ”关键字来使用别名

     extern alias log4net_1_2_10_0; using log4net_1_2_10_0.log4net; using System.Web; ... 
  8. Add codebases into your config file. 将代码库添加到配置文件中。 Those should refer to the dll you placed into your folder, with the proper version and token. 这些应该引用您放入文件夹的dll,以及正确的版本和令牌。

     <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> 

You can reference diferent versions of the same dll using Alias , as is explained here MSDN : 您可以使用Alias引用相同dll的不同版本,如MSDN中所述

Add the reference to both the dlls in your client application solution. 在客户端应用程序解决方案中添加对这两个dll的引用。 Then in the Solution Explorer under the reference node select the first (old version) class library. 然后在引用节点下的Solution Explorer中选择第一个(旧版本)类库。 In the property window change Aliases field from global to oldVer. 在属性窗口中,将Aliases字段从global更改为oldVer。 Make similar change after selecting the newer class library as well. 选择较新的类库后也要进行类似的更改。 You are then good to go… 你很高兴去...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在LINQPad中引用同一程序集的两个不同版本 - reference two different version of the same assembly in LINQPad 引用针对不同平台的同一程序集的不同版本 - Reference different version of same assembly targeted for different Platforms 使用Prism,两个模块是否可以引用同一装配体的不同版本? - With Prism, is it possible for two modules to reference different versions of the same assembly? 可以在一个项目中引用两个具有相同名称的不同程序集吗? 不同的二进制文件 - Possible to reference two different assemblies with the same name in a project? different binaries 是否可以通过反射引用特定版本的装配? - Is it possible to reference specific version of assembly via reflection? 每个版本引用不同的程序集版本? - Reference different assembly version per build? 引用同一程序集中的不同项目,不同的名称空间 - Referencing a different project in the same assembly, different namespaces 同一解决方案中的项目到项目参考特定版本 - Project to Project reference specific Version in same solution 引用两个程序集,每个引用另一个程序集,但版本不同 - Reference to two assemblies, each one with reference to the another assembly but with different version 是否可以在.Net中的不同项目中使用相同的程序集? - Is it possible to work on the same assembly in different projects in .Net?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM