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

时间:2023-01-06 07:31:05

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 \中查看该文件

10 个解决方案

#1


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. 打开Windows运行对话框(Windows键+ r)

  3. 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)
  4. 键入C:\ Windows \ assembly \ gac_msil。这是一种奇怪的黑客攻击,可让您浏览GAC。您只能通过运行对话框访问它。希望我传播此信息最终不会导致Microsoft修补它并阻止它。 (太偏执了?:P)

  5. Find your assembly and copy its path from the address bar.
  6. 找到您的程序集并从地址栏复制其路径。

  7. Open the Add Reference dialog in Visual Studio and choose the Browse tab.
  8. 在Visual Studio中打开“添加引用”对话框,然后选择“浏览”选项卡。

  9. Paste in the path to your GAC assembly.
  10. 粘贴到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程序集放在一起,以确保在以后需要使用远程调试程序时它们不会丢失。

#2


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将允许您从Add GAC Reference菜单项向项目添加Global Assembly Cache引用。

Hope this helps Muse VSExtensions

希望这有助于Muse VSExtensions

#3


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中不会在“添加引用”对话框中放置对程序集的引用。您仍然需要按项目的路径引用程序集,主要区别在于您不需要使用copy local选项,您的应用程序将在运行时找到它。

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可再发行组件。

#4


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等。

#5


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

这就是你想要在大多数时间里做这件事的方式。然而,经过一番探索后,我在MS Connect上发现了这个问题。 MS表示这是一个已知的部署问题,他们没有解决方法。该家伙说,如果他从GAC文件夹中复制dll并将其放入他的垃圾箱,它就可以了。

#6


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。

#7


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 post it is a known issue.

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

And this could be the solution you're looking for :)

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

#8


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. 把你的dll放在GAC中(对于3.5 Drag Drop in“C:\ Windows \ assembly \”)

  3. GoTo Projects --> Properties
  4. GoTo Projects - > Properties

  5. Click Reference Path (for 3.5 it's "C:\Windows\assembly\")
  6. 单击引用路径(对于3.5它是“C:\ Windows \ assembly \”)

  7. and Build

Hope it helps

希望能帮助到你

#9


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.

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

#10


I found this extension for VS 2013 Vitevic GAC Reference.

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

#1


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. 打开Windows运行对话框(Windows键+ r)

  3. 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)
  4. 键入C:\ Windows \ assembly \ gac_msil。这是一种奇怪的黑客攻击,可让您浏览GAC。您只能通过运行对话框访问它。希望我传播此信息最终不会导致Microsoft修补它并阻止它。 (太偏执了?:P)

  5. Find your assembly and copy its path from the address bar.
  6. 找到您的程序集并从地址栏复制其路径。

  7. Open the Add Reference dialog in Visual Studio and choose the Browse tab.
  8. 在Visual Studio中打开“添加引用”对话框,然后选择“浏览”选项卡。

  9. Paste in the path to your GAC assembly.
  10. 粘贴到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程序集放在一起,以确保在以后需要使用远程调试程序时它们不会丢失。

#2


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将允许您从Add GAC Reference菜单项向项目添加Global Assembly Cache引用。

Hope this helps Muse VSExtensions

希望这有助于Muse VSExtensions

#3


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中不会在“添加引用”对话框中放置对程序集的引用。您仍然需要按项目的路径引用程序集,主要区别在于您不需要使用copy local选项,您的应用程序将在运行时找到它。

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可再发行组件。

#4


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等。

#5


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

这就是你想要在大多数时间里做这件事的方式。然而,经过一番探索后,我在MS Connect上发现了这个问题。 MS表示这是一个已知的部署问题,他们没有解决方法。该家伙说,如果他从GAC文件夹中复制dll并将其放入他的垃圾箱,它就可以了。

#6


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。

#7


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 post it is a known issue.

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

And this could be the solution you're looking for :)

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

#8


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. 把你的dll放在GAC中(对于3.5 Drag Drop in“C:\ Windows \ assembly \”)

  3. GoTo Projects --> Properties
  4. GoTo Projects - > Properties

  5. Click Reference Path (for 3.5 it's "C:\Windows\assembly\")
  6. 单击引用路径(对于3.5它是“C:\ Windows \ assembly \”)

  7. and Build

Hope it helps

希望能帮助到你

#9


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.

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

#10


I found this extension for VS 2013 Vitevic GAC Reference.

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