C# 如何引用多版本程序集

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4930/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-07-31 16:23:26  来源:igfitidea点击:

How to reference to multiple version assembly

提问by Fajar

I'm developing a Sharepoint application and use .NET AjaxControlToolkit library, we are adding a custom aspx page to the Sharepoint. Sharepoint 2007 run in quirks mode so I've made some modification to the AJAX library to make it behave like it normally should. The problem is, the other team already uses the AJAX library and it is a different version with mine. This caused conflict because there could be only one dll in the bin folder with the same name.

我正在开发一个 Sharepoint 应用程序并使用 .NET AjaxControlToolkit 库,我们正在向 Sharepoint 添加一个自定义 aspx 页面。Sharepoint 2007 在 quirks 模式下运行,因此我对 AJAX 库进行了一些修改,使其行为正常。问题是,另一个团队已经使用了 AJAX 库,它与我的版本不同。这引起了冲突,因为 bin 文件夹中可能只有一个同名的 dll。

From what I know, .NET should be able to handle this situation easily. I've tried using a strong name and GAC to solve it, but it still refers to the dll in the bin folder. If there is no AjaxControlToolkit.dll in the bin folder, the application will simply fail to load the assembly.

据我所知,.NET 应该能够轻松处理这种情况。我试过使用强名称和GAC来解决它,但它仍然指的是bin文件夹中的dll。如果 bin 文件夹中没有 AjaxControlToolkit.dll,应用程序将无法加载程序集。

If I use complete assembly information on my like this

如果我像这样使用完整的装配信息

<%@ 
    Register 
    tagprefix="AjaxControlToolkit"
    namespace="AjaxControlToolkit"
    assembly="AjaxControlToolkit, Version=1.0.299.18064, 
    PublicKeyToken=12345678abcdefgh, 
    Culture=neutral"
%>

It gives me Compiler Error CS0433

它给了我编译器错误 CS0433

Can someone help me on how to use multiple version of assembly in an application?

有人可以帮助我如何在应用程序中使用多个版本的程序集吗?

回答by Vivek

Well the link for Compiler Error CS0433makes it pretty clear that the core issue is not with multiple versions of the assembly being referenced - but with namespace + typename conflicts.

编译器错误 CS0433的链接清楚地表明,核心问题不在于引用的程序集的多个版本 - 而是命名空间 + 类型名冲突。

When you load up / reference a type - the compiler can't resolve which DLL to load that type from. If Sharepoint is going to load both your DLLs versions (as you say it needs to) - this error will always come.

当您加载/引用一个类型时 - 编译器无法解析从哪个 DLL 加载该类型。如果 Sharepoint 将加载您的两个 DLL 版本(正如您所说的那样) - 此错误将始终出现。

Simplest fix would be to change the namespaces in the new DLL, since it does have your custom tweaks, and you control the code - mark it clearly as well.

最简单的解决方法是更改​​新 DLL 中的命名空间,因为它确实有您的自定义调整,并且您可以控制代码 - 也将其标记清楚。