如何从 Visual Studio 引用 GAC 中的 dll?
此程序集位于 GAC 中:Microsoft.SqlServer.Management.RegisteredServers.dll
如何在 Visual Studio 中添加对此程序集的引用?
我可以在 c:\windows\Assembly\ 中查看该文件
This assembly is in the GAC: Microsoft.SqlServer.Management.RegisteredServers.dll
How can I add a reference to this assembly in Visual Studio?
I can view the file in c:\windows\assembly\
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
正如其他人所说,大多数时候您不想这样做,因为它不会将程序集复制到您的项目中,并且不会与您的项目一起部署。 但是,如果您像我一样,并尝试添加所有目标计算机在其 GAC 中都有的引用,但它不是 .NET Framework 程序集:
我不知道是否有更简单的方法,但我还没有找到。 我还经常使用步骤 1-3 将 .pdb 文件与其 GAC 程序集一起放置,以确保当我稍后需要使用远程调试器时它们不会丢失。
As the others said, most of the time you won't want to do that because it doesn't copy the assembly to your project and it won't deploy with your project. However, if you're like me, and trying to add a reference that all target machines have in their GAC but it's not a .NET Framework assembly:
I don't know if there's an easier way, but I haven't found it. I also frequently use step 1-3 to place .pdb files with their GAC assemblies to make sure they're not lost when I later need to use Remote Debugger.
将程序集注册到 GAC 后不会在添加引用对话框中放置对该程序集的引用。 您仍然需要通过项目的路径引用程序集,主要区别是您不需要使用复制本地选项,您的应用程序将在运行时找到它。
在这种特殊情况下,您只需要通过路径(浏览)引用程序集,或者如果您确实希望将其包含在添加引用对话框中,则可以通过注册表设置添加其他路径。
请注意,如果您将应用程序发送给未安装此程序集的人,您将需要发送它,在这种情况下,您确实需要使用 SharedManagementObjects.msi 可再发行组件。
Registering assmblies into the GAC does not then place a reference to the assembly in the add references dialog. You still need to reference the assembly by path for your project, the main difference being you do not need to use the copy local option, your app will find it at runtime.
In this particular case, you just need to reference your assembly by path (browse) or if you really want to have it in the add reference dialog there is a registry setting where you can add additional paths.
Note, if you ship your app to someone who does not have this assembly installed you will need to ship it, and in this case you really need to use the SharedManagementObjects.msi redistributable.
我创建了一个完全免费的工具,它将帮助您实现目标。 Muse VSReferences 将允许您从“添加 GAC 引用”菜单项向项目添加全局程序集缓存引用。
希望这会有所帮助Muse VSExtensions
I've created a tool which is completely free, that will help you to achieve your goal. Muse VSReferences will allow you to add a Global Assembly Cache reference to the project from Add GAC Reference menu item.
Hope this helps Muse VSExtensions
在 VS2010 中,从“添加引用”窗口中,您可以单击“浏览”并导航到 C:\Windows\Assembly,然后添加对所需程序集的引用。 请注意,这些文件可能分组在不同的文件夹下,例如 GAC、GAC_32、GAC_64、GAC_MSIL 等。
In VS2010, from the Add Rerences window you can click 'Browse' and navigate to C:\Windows\Assembly and add references to the assemblies that you want. Please note that the files may be grouped under different folders like GAC, GAC_32, GAC_64, GAC_MSIL etc.
在 VS 中,右键单击您的项目,选择“添加引用...”,您将看到 GAC 中存在的所有命名空间。 选择 Microsoft.SqlServer.Management.RegisteredServers 并单击“确定”,您应该可以开始
编辑:
这就是您大多数时候想要执行此操作的方式。 但是,经过一番研究后,我发现此问题在 MS Connect 上。 MS 表示这是一个已知的部署问题,他们没有解决方法。 那家伙说,如果他从 GAC 文件夹中复制 dll 并将其放入他的垃圾箱中,它就可以工作。
In VS, right click your project, select "Add Reference...", and you will see all the namespaces that exist in your GAC. Choose Microsoft.SqlServer.Management.RegisteredServers and click OK, and you should be good to go
EDIT:
That is the way you want to do this most of the time. However, after a bit of poking around I found this issue on MS Connect. MS says it is a known deployment issue, and they don't have a work around. The guy says if he copies the dll from the GAC folder and drops it in his bin, it works.
对我有用的唯一方法是将 dll 复制到桌面或其他位置,添加对它的引用,然后从桌面删除 dll。
Visual Studio 将刷新自身,并最终从 GAC 自身引用 dll。
The only way that worked for me, is by copying the dll into your desktop or something, add reference to it, then delete the dll from your desktop.
Visual Studio will refresh itself, and will finally reference the dll from the GAC on itself.
假设您已经尝试按照上面的说明“添加引用...”但没有成功,您可以查看 此处。 他们说你必须满足一些先决条件:
- .NET 3.5 SP1
- Windows Installer 4.5
编辑:根据此帖子,它是一个已知问题。
这可能就是您正在寻找的解决方案:)
Assuming you alredy tried to "Add Reference..." as explained above and did not succeed, you can have a look here. They say you have to meet some prerequisites:
- .NET 3.5 SP1
- Windows Installer 4.5
EDIT: According to this post it is a known issue.
And this could be the solution you're looking for :)
也许现在回答已经太晚了,但我找到了一种非常简单的方法来做到这一点(无需破解)。
希望它会有所帮助
May be it's too late to answer, but i found a very simple way to do this(without a hack).
Hope it helps
相关文件和参考可以在这里找到:
http://msdn.microsoft.com /en-us/library/cc283981.aspx
请注意其中有关实现/等的链接。
The relevant files and references can be found here:
http://msdn.microsoft.com/en-us/library/cc283981.aspx
Note the links off it about implementation/etc.
我找到了 VS 2013 Vitevic GAC 参考的此扩展。
I found this extension for VS 2013 Vitevic GAC Reference.