如何从 Visual Studio 引用 GAC 中的 dll?

发布于 2024-07-12 00:29:07 字数 154 浏览 10 评论 0原文

此程序集位于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

爱本泡沫多脆弱 2024-07-19 00:29:07

正如其他人所说,大多数时候您不想这样做,因为它不会将程序集复制到您的项目中,并且不会与您的项目一起部署。 但是,如果您像我一样,并尝试添加所有目标计算机在其 GAC 中都有的引用,但它不是 .NET Framework 程序集:

  1. 打开 Windows 运行对话框(Windows 键 + r)
  2. 键入 C:\Windows\ assembly \gac_msil。 这是某种奇怪的 hack,可以让你浏览你的 GAC。 您只能通过运行对话框来访问它。 希望我传播此信息最终不会导致微软修补并阻止它。 (太偏执了?:P)
  3. 找到您的程序集并从地址栏复制其路径。
  4. 在 Visual Studio 中打开“添加引用”对话框,然后选择“浏览”选项卡。
  5. 粘贴到您的 GAC 程序集的路径。

我不知道是否有更简单的方法,但我还没有找到。 我还经常使用步骤 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:

  1. Open the windows Run dialog (Windows Key + r)
  2. Type C:\Windows\assembly\gac_msil. This is some sort of weird hack that lets you browse your GAC. You can only get to it through the run dialog. Hopefully my spreading this info doesn't eventually cause Microsoft to patch it and block it. (Too paranoid? :P)
  3. Find your assembly and copy its path from the address bar.
  4. Open the Add Reference dialog in Visual Studio and choose the Browse tab.
  5. Paste in the path to your GAC 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.

风尘浪孓 2024-07-19 00:29:07

将程序集注册到 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.

多情出卖 2024-07-19 00:29:07

我创建了一个完全免费的工具,它将帮助您实现目标。 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

骑趴 2024-07-19 00:29:07

在 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.

本王不退位尔等都是臣 2024-07-19 00:29:07

在 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.

小巷里的女流氓 2024-07-19 00:29:07

对我有用的唯一方法是将 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.

甲如呢乙后呢 2024-07-19 00:29:07

假设您已经尝试按照上面的说明“添加引用...”但没有成功,您可以查看 此处。 他们说你必须满足一些先决条件:
- .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 :)

薄荷→糖丶微凉 2024-07-19 00:29:07

也许现在回答已经太晚了,但我找到了一种非常简单的方法来做到这一点(无需破解)。

  1. 将您的 dll 放入 GAC 中(对于 3.5 拖放到 "C:\Windows\ assembly\" 中)
  2. 转到项目 --> 属性
  3. 单击参考路径(对于 3.5,它是“C:\Windows\ assembly\”
  4. 并构建

希望它会有所帮助

May be it's too late to answer, but i found a very simple way to do this(without a hack).

  1. Put your dll in GAC (for 3.5 Drag Drop inside "C:\Windows\assembly\")
  2. GoTo Projects --> Properties
  3. Click Reference Path (for 3.5 it's "C:\Windows\assembly\")
  4. and Build

Hope it helps

情深已缘浅 2024-07-19 00:29:07

相关文件和参考可以在这里找到:

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.

祁梦 2024-07-19 00:29:07

我找到了 VS 2013 Vitevic GAC 参考的此扩展。

I found this extension for VS 2013 Vitevic GAC Reference.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文