关于GAC(全局程序集缓存) [英] Regarding GAC ( Global Assembly Cache)

查看:310
本文介绍了关于GAC(全局程序集缓存)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在GAC注册了一个DLL。但是我想知道如何使用DLL。





不要让我在运行时创建一个汇编对象继续。我只是想将它添加到我的项目参考中。



我还找到了一个将dll添加到C的替代方案:\ Windows \ Myrosoft.Net \ Framework \vxxx \

并且它正在运行。但是这里的另一个问题是将dll复制到上面说的路径工作而没有将dll注册到GAC。





我只是需要一种方法来添加已经添加到GAC中的dll作为我的新项目的参考。



提前感谢。

解决方案

当程序集(它的程序集,而不是DLL;对于.NET,这只不过是其中一个程序集的模块名称)放在GAC中时,你应该不要通过装配位置来引用它。从这一刻起,你必须通过它的强名来引用它。使用Visual Studio,您可以在添加引用窗口的.NET选项卡中找到它。



-SA


您必须首先了解为什么要将程序集放置到GAC:GAC拥有各种版本的强名称签名程序集。每个.NET可执行文件在运行时查找 * * 在定义明确的序列中直接或间接引用的程序集,同时也在GAC中查找。请参阅运行时如何查找程序集 [ ^ ]。



当它是关于 *开发* 这些依赖于其他程序集的应用程序,您可以,但不需要在开发时从GAC *引用它* 。该引用仅用于首先访问引用的程序集公开的功能,其次,用于将相应的强名称编译到应用程序程序集中。您现在可能将该程序集放在某个持久位置(例如ProgramFiles中的某个位置),然后将其置于GAC中(以管理员身份运行一次:gacutil / i ...)并最终引用VS2010中的ProgramFiles程序集。



注意:VS2010在程序集的任何路径中都 * not * 编译。项目中的所有引用都不会进入程序集 - 只有真正需要的引用才能编译到应用程序中。



例如如果您运行 ildasm / text myApp.exe |更多,并查找 .extern ,您可以看到哪些程序集引用了哪些版本等。没有路径,只有名称,版本,文化,公共令牌。



干杯

Andi


< blockquote>你永远不应该在C:\ Windows \ MyMicrosoft.NET文件夹中放置任何东西。它们严格用于.NET Framework。你有一个共享库,被多个应用程序使用,然后你可以根据你的要求签名并将它放在GAC或其他地方,但是永远不要在C:\ Windows \ Microsoft.NET下

I''ve registered a DLL in GAC. But I want to know how can I use the DLL.


Don''t ask me to create a assembly object at runtime and proceed. I just want to add it to my project reference.

Also I found a alternate of adding the dll to the C:\Windows\Microsoft.Net\Framework\v.x.x.x\
and it''s working. But here the another problem is copying the dll to the above said path is working without registering the dll to GAC.


All I just need is a way to add the dll already added in the GAC as a reference to my new project.

Thanks in advance.

解决方案

When the assembly (it''s assembly, not "DLL"; for .NET, this is no more than a name of the modules of one of the assemblies) is placed in GAC, you should not reference it by assembly location. From this moment, you have to reference it by its strong name. With Visual Studio, you will find it by name in the ".NET" tab of the "Add Reference" window.

—SA


You must first understand why you want to place an assembly to the GAC at all: the GAC holds strong named signed assemblies of various versions. Each .NET executable looks up *at runtime* the directly or indirectly referenced assemblies in a well defined sequence, at one point also in the GAC. See How the Runtime Locates Assemblies[^].

When it is about *developing* such applications that depend on other assemblies, you can, but do not need to reference it from the GAC *at development time*. The reference is only used to first have access to the functionality exposed by the referenced assembly and secondly, to compile in the respective strong name into your application assembly. You may now have that assembly located in some persistent location (e.g. somewhere in ProgramFiles), then have it once registered in the GAC (running once as administrator: gacutil /i ...) and finally refer to the ProgramFiles assembly in your VS2010.

Note: the VS2010 does *not* compile in any path to an assembly. Neither do all the references in your project get their way into the assembly - only the really needed ones get compiled into the application.

E.g. if you run ildasm /text myApp.exe | more, and look for .extern, you see which assemblies with what version, etc. are referenced. No path there, only the name, version, culture, public token.

Cheers
Andi


You should NEVER place anything in the C:\Windows\Microsoft.NET folders. They are strictly for the .NET Framework. It you have a shared library that''s used by more than one application, then you can sign it and put it in the GAC or some other place as your requirements dictates, but NEVER under C:\Windows\Microsoft.NET.


这篇关于关于GAC(全局程序集缓存)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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