[英]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,我会写下整个过程。
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; ...
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.