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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/444655/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:04:13  来源:igfitidea点击:

How can I reference a dll in the GAC from Visual Studio?

visual-studioassembliesgac

提问by xr280xr

This assembly is in the GAC: Microsoft.SqlServer.Management.RegisteredServers.dll

这个程序集在 GAC 中:Microsoft.SqlServer.Management.RegisteredServers.dll

How can I add a reference to this assembly in Visual Studio?

如何在 Visual Studio 中添加对此程序集的引用?

I can view the file in c:\windows\assembly\

我可以在 c:\windows\assembly\ 中查看文件

回答by xr280xr

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:

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

  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.
  1. 打开 Windows 运行对话框(Windows 键 + r)
  2. 键入 C:\Windows\assembly\gac_msil。这是一种让您浏览 GAC 的奇怪技巧。您只能通过运行对话框访问它。希望我传播此信息最终不会导致 Microsoft 对其进行修补和阻止。(太偏执了?:P)
  3. 找到您的程序集并从地址栏中复制其路径。
  4. 在 Visual Studio 中打开“添加引用”对话框并选择“浏览”选项卡。
  5. 粘贴到您的 GAC 程序集的路径中。

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.

我不知道是否有更简单的方法,但我还没有找到。我还经常使用步骤 1-3 将 .pdb 文件与它们的 GAC 程序集一起放置,以确保它们在我以后需要使用远程调试器时不会丢失。

回答by Tim Jarvis

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.

将程序集注册到 GAC 后不会在添加引用对话框中放置对程序集的引用。您仍然需要按路径为您的项目引用程序集,主要区别在于您不需要使用复制本地选项,您的应用程序将在运行时找到它。

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.

请注意,如果您将应用程序发送给未安装此程序集的人,您将需要发送它,在这种情况下,您确实需要使用 SharedManagementObjects.msi 可再发行组件。

回答by BALKANGraph

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.

我创建了一个完全免费的工具,它将帮助您实现目标。Muse VSReferences 将允许您从“添加 GAC 引用”菜单项中向项目添加全局程序集缓存引用。

Hope this helps Muse VSExtensions

希望这有助于Muse VSExtensions

回答by Manesh

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.

在 VS2010 中,您可以从 Add Rerences 窗口单击“Browse”并导航到 C:\Windows\Assembly 并添加对所需程序集的引用。请注意,这些文件可能会分组在不同的文件夹下,例如 GAC、GAC_32、GAC_64、GAC_MSIL 等。

回答by Matt Briggs

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

在 VS 中,右键单击您的项目,选择“添加引用...”,您将看到 GAC 中存在的所有命名空间。选择 Microsoft.SqlServer.Management.RegisteredServers 并单击 OK,您应该很高兴

EDIT:

编辑:

That is the way you want to do this most of the time. However, after a bit of poking around I found this issueon 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.

大多数时候,这就是您想要执行此操作的方式。但是,经过一番摸索后,我在 MS Connect 上发现了这个问题。MS 说这是一个已知的部署问题,他们没有解决方法。这家伙说,如果他从 GAC 文件夹中复制 dll 并将其放入他的 bin 中,它就可以工作。

回答by Ahmed IG

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.

对我有用的唯一方法是将 dll 复制到您的桌面或其他东西,添加对它的引用,然后从您的桌面删除 dll。Visual Studio 将自行刷新,并最终在自身上引用来自 GAC 的 dll。

回答by Stefano Driussi

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

假设您已经尝试如上所述“添加引用...”但没有成功,您可以查看这里。他们说你必须满足一些先决条件: - .NET 3.5 SP1 - Windows Installer 4.5

EDIT: According to this postit is a known issue.

编辑:根据这篇文章,这是一个已知问题。

And thiscould be the solution you're looking for :)

可能是你正在寻找的解决方案:)

回答by Vinod Srivastav

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

可能现在回答为时已晚,但我找到了一种非常简单的方法来做到这一点(没有 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
  1. 将你的 dll 放在GAC 中(对于 3.5 Drag Drop inside "C:\Windows\assembly\"
  2. 转到项目 --> 属性
  3. 单击参考路径(对于 3.5,它是"C:\Windows\assembly\"
  4. 和建造

Hope it helps

希望能帮助到你

回答by Devlin

I found this extension for VS 2013 Vitevic GAC Reference.

我为 VS 2013 Vitevic GAC Reference找到了这个扩展。

回答by winwaed

The relevant files and references can be found here:

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

http://msdn.microsoft.com/en-us/library/cc283981.aspx

http://msdn.microsoft.com/en-us/library/cc283981.aspx

Note the links off it about implementation/etc.

请注意有关实现/等的链接。