本文介绍了我可以引用在同一个项目一个DLL的两个版本没有把他们在GAC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以参考在同一个项目一个DLL的两个版本没有把他们在GAC?

Can I reference two versions of a dll in the same project without putting them in the GAC?

感谢

推荐答案

您已经有了两个问题。第一个是让你的应用程序进行编译。你必须包含与类型相同的命名空间名称和类型名称的两个程序集引用,编译器将不知道该选哪一个。你解决,通过使用外部别名,它可以让你重新命名组件之一的命名空间。回顾。

You've got two problems. First one is getting your app to compile. You've got two assembly references that contain types with the same namespace name and type name, the compiler won't know which one to choose. You solve that by using "extern alias", it lets you rename the namespace of one of the assemblies. Review this question for further help.

第二个问题是你问的人。如果没有GAC,你需要帮助的CLR找到正确的DLL。你必须把DLL文件在一个单独的目录,说你的build目录的子目录,这样CLR无法找到他们。使用后生成事件来创建此目录和DLL文件复制到他们。给他们不同的名字。

The second problem is the one you ask about. Without the GAC, you need to help the CLR finding the correct DLL. You must put the DLLs in a separate directory, say a subdirectory of your build directory, so that the CLR cannot find them. Use a post build event to create this directory and copy the DLLs into them. Give them distinct names.

然后实现AppDomain.CurrentDomain.AssemblyResolve事件。 CLR会触发它时,它无法找到你隐藏的DLL。使用Assembly.LoadFrom()加载并返回它要求大会。该e.Name酒店有完整的程序集名称,使用的AssemblyName类来解析该字符串和检索版本属性。

Then implement the AppDomain.CurrentDomain.AssemblyResolve event. The CLR will fire it when it cannot find the DLLs you've hidden. Use Assembly.LoadFrom() to load and return the assembly it asks for. The e.Name property has the full assembly name, use the AssemblyName class to parse that string and retrieve the Version property.

这篇关于我可以引用在同一个项目一个DLL的两个版本没有把他们在GAC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 03:27