从Visual Studio中的GAC引用DLL [英] Referencing DLL from GAC in Visual Studio

查看:177
本文介绍了从Visual Studio中的GAC引用DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我环顾四周,试图找到一些帖子,有很多但没有一个解决我的具体问题(我可以找到)。

So I've looked around to try to find some posts on this and there are many but none that address my specific question (that I could find).

我正在尝试在我的项目中添加一些DLL,但很少是来自:

I am trying to add some DLL's in my project but few of them are coming from :

C:\Windows\Microsoft.NET\Framework\v3.5\XXX.YYY.dll

我期望这应该来自GAC。

and what I expecting this should be coming from GAC.

请建议我参考Visual Studio中的Dll的最佳做法。

Please suggest me the best practice to reference the Dll's in Visual Studio.

推荐答案

这不是它的工作方式。当您使用Project + Add Reference时,您始终添加参考程序集。这是从GAC来的永远不要的程序集。 GAC是一个运行时实现细节,它只用于在程序执行时提供程序集,而不是在构建程序时使用。

That's not the way it works. When you use Project + Add Reference then you always add a reference assembly. This is never an assembly from the GAC. The GAC is a runtime implementation detail, it is only ever used to supply assemblies when your program executes, never when it is built.

它的工作非常重要方式,您机器上GAC的内容与用户机器上GAC的内容不符。使用了很多DLL Hell对策,以确保当用户的机器配置不正确以执行程序时,将引用程序集与用户的GAC内容映射到良好的诊断。

It is very important that it works that way, the content of the GAC on your machine will not match the content of the GAC on your user's machine. Lots of DLL Hell countermeasures are in place to ensure the mapping of your reference assembly to the user's GAC content is taken care of with good diagnostics when the user's machine isn't configured correctly to execute your program.

这也是当您使用资源管理器导航到c:\windows\assembly时无法直接查看GAC文件夹的原因。外壳扩展处理程序隐藏细节,阻止您将添加GAC-ed程序集作为参考程序集的错误。不会为.NET 4程序集安装同样的扩展处理程序,您可以查看c:\windows\microsoft.net\assembly并查看GAC的结构。不要以为现在可以从中添加引用,引用程序集在.NET 4中更重要,它们与运行时程序集完全不同。

This is also the reason that you cannot directly look at the GAC folders when you navigate to c:\windows\assembly with Explorer. A shell extension handler hides the details to stop you from making a mistake like adding a GAC-ed assembly as a reference assembly. This same extension handler is not installed for the .NET 4 assemblies, you can look at c:\windows\microsoft.net\assembly and see the structure of the GAC. Do not assume that it is now okay to add references from there, reference assemblies are even more important in .NET 4, they are completely different from the runtime assemblies.

所以看到存储在C:\Windows\Microsoft.NET\Framework\v3.5中的引用程序集完全正常,那就是主目录。 NET 3.5特定的引用程序集,如System.Core.dll。对于.NET 4项目,引用程序集存储在c:\program files\reference程序集中,它们应该引用C:\Windows\Microsoft.NET\Framework\v4。 0.30319。检查此答案看看不使用正确的参考组件可能导致什么样的不可判定的苦难。

So seeing the reference assembly stored in C:\Windows\Microsoft.NET\Framework\v3.5 is completely normal, that's the home directory for .NET 3.5 specific reference assemblies, like System.Core.dll. For .NET 4 projects the reference assemblies are stored in c:\program files\reference assemblies, they should not reference C:\Windows\Microsoft.NET\Framework\v4.0.30319. Check this answer to see what kind of undiagnosable misery can be caused by not using the correct reference assemblies.

这篇关于从Visual Studio中的GAC引用DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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