如何引用 GAC 的程序集?
我已将强命名程序集 TestReflection
安装到 GAC 中(我使用的是 .NET 4.0 和 VS 2010)。
不同版本的 TestReflection
DLL 位于 .NET 4.0 的 GAC (C:\WINDOWS\Microsoft.NET\ assembly\GAC_32\TestReflection\
) 中,但是,程序集确实没有出现在“项目”-> VS 2010 的“添加引用”框。
如何在设计时从另一个项目引用部署在 GAC 中的程序集?
此页面显示:
您无法添加来自全局程序集缓存 (GAC) 的引用,因为它严格来说是运行时环境的一部分。
参考这个说法,我想知道如果需要的话,如何使您的项目的DLL共享程序集供其他使用者使用?
I have installed the strong named assembly TestReflection
into the GAC (I am using .NET 4.0 and VS 2010).
Different versions of the TestReflection
DLL are in GAC of .NET 4.0 (C:\WINDOWS\Microsoft.NET\assembly\GAC_32\TestReflection\
), however, the assembly does not appear in the "Project" -> "Add reference" box of VS 2010.
How can I refer to my assembly deployed in GAC at design time from another project?
This page says that:
You cannot add references from the Global Assembly Cache (GAC), as it is strictly part of the run-time environment.
Referring to this statement, I would like to know how to make your project's DLL shared assembly for other consumers if it's the requirement?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
“添加引用”对话框的 .Net 选项卡中显示的 dll 实际上并不是在 GAC 中注册的。通过搜索文件系统上的一些路径可以找到它们。
Visual Studio 通过查找以下注册表项来定位正在搜索的路径:
应该已经添加了一些键,因此如果您希望自己的 dll 显示在 .Net 选项卡上,可以将其添加到其中之一那里定义的文件夹。您还可以添加一个指向自定义文件夹的新注册表项,该文件夹仅包含您自己的 dll。
GAC 仅用于在部署应用程序后在运行时加载程序集,因此我认为您不应该在开发时使用它。当您部署应用程序时,请确保在引用上将“复制本地”设置为 false,以便 dll 不会被复制到 bin 文件夹,然后将其安装到 GAC 中,并从那里加载。
The dll's shown in the .Net tab of the "Add references" dialog are not actually the ones registered in the GAC. They are found by searching a few paths on your filesystem.
The paths being searched are located by Visual Studio by looking up the following registry entries:
There should be some keys added there already, so if you want your own dll to show up on the .Net tab, you can add it to one of the folders defined there. You could also add a new registry key pointing to a custom folder, which would only contain your own dll's.
The GAC is only meant for loading assemblies at runtime after your application has been deployed, so I don't think you should use it while developing. When you deploy your app, make sure to set "Copy local" to false on your reference so the dll won't be copied to the bin folder, and then install it into the GAC and it will be loaded from there instead.
另一个简单的选择是在 Visual Studio 中手动将项目文件编辑为 XML(您必须先卸载项目),然后只需添加节点
在 MSBuild 项目文件中。重新加载项目后,VS 将毫无问题地获取引用。Another simple option would be to manually edit the project file as XML in visual studio (You will have to unload the project first), and simply add node
<Reference Include="<name of dll>" />
in MSBuild project file. After reloading the project, VS will pick up the reference without problem.如果要将全局程序集缓存引用添加到 VS2010 项目,可以使用一个扩展:Muse.VSExtensions。
它有一些怪癖,但做得还不错。一探究竟...
If you want to add Global Assembly Cache references to your VS2010 project, there is an extension you can use: Muse.VSExtensions.
It has some quirks but does a decent job. Check it out...
答案是属性窗口中的Reference Paths,你必须用GAC路径来设置它
请在此处查看我的帖子:
The answer is the Reference Paths in the property windows, you have to set it with the GAC path
Please see my post here: