如何引用具有相同名称的不同程序集? [英] How to reference different assemblies with the same name?

查看:58
本文介绍了如何引用具有相同名称的不同程序集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个具有相同名称的不同程序集,需要添加到我的项目中.

I have 2 different assemblies with the same name I need to add to my project.

当我尝试将两个引用都添加到项目中时,Visual Studio告诉我已经引用了该程序集(因为已经有一个具有相同名称的程序集).

When I try to add both references to the project, visual studio tells me the assembly is already referenced (because there is already an assembly with the same name).

我尝试重命名其中一个文件.我可以添加两个引用,但是,当从重命名的程序集访问方法时,解决它失败(因为.net尝试使用原始名称加载程序集).

I tried renaming one of the files. I could add both references but then, when accessing methods from the renamed assembly, resolving it fails (because .net tries to load the assembly with the original name).

注意:程序集不是我的程序集,因此我不能更改其内容.

Note: The assemblies are not mine, therefore I cant change their contents.

推荐答案

如果它们是经过严格签名并具有不同的公钥的,则可以尝试以下方法:

If they are strongly signed and have different public keys maybe you can try this:

具有一个单独的库项目,用于包装两个程序集之一.这样,您可以为其中一个选择不同的名称和名称空间,然后直接引用两个程序集之一,并间接引用另一个程序集.

Have a separate library project for wrapping one of the two assemblies. That way you can choose a different name and namespace for one of them and then reference one of the two assemblies directly and the other indirectly.

挑战在于,如果两个程序集都具有相同的文件名,则在运行时不能将它们放在同一文件夹中.由于它们是经过严格签名的,因此您可以将它们都放入全局程序集缓存(GAC)中,也可以在运行时将两者之一放在子文件夹中,然后将该子文件夹添加到探测路径中.

The challenge will be that if both assemblies have the same file name you cannot have them in the same folder during runtime. As they are strongly signed you can put them both into the Global Assembly Cache (GAC) or you can put one of the two in a subfolder during runtime and add that subfolder to the probing path.

祝你好运!

这篇关于如何引用具有相同名称的不同程序集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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