如何在Visual Studio中引用安装在GAC中的自制组件?

时间:2023-01-06 07:30:59

I created a homemade assembly and I think I installed it correctly in the GAC using the .Net 2.0 configuration tool (mscorcfg.msu) However, when I want to reference it in visual studio, where do I find it?

我创建了一个自制的程序集,我想我使用.Net 2.0配置工具(mscorcfg.msu)在GAC中正确安装了它。但是,当我想在visual studio中引用它时,我在哪里可以找到它?

( I know, I should not use the GAC anyway, but indulge me ;-))

(我知道,无论如何我不应该使用GAC,而是放纵我;-))

EDIT: I did not ask the question clear enough: After installing the assembly to the GAC, it does not show up on the .NET tab of the Project-Add Reference menu.

编辑:我没有问清楚这个问题:将程序集安装到GAC后,它没有显示在Project-Add Reference菜单的.NET选项卡上。

3 个解决方案

#1


The add reference dialog actually looks at the registry, in particular:

添加引用对话框实际上是查看注册表,特别是:

  • [HKEY_LOCAL_MACHINE]\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders
  • [HKEY_CURRENT_USER]\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders

To add your assembly, you must edit these registry keys. Or simply using the "Browse..." button (instead) may be more tempting.

要添加程序集,必须编辑这些注册表项。或者只是使用“浏览...”按钮(而不是)可能更具吸引力。

#2


When you need to reference an assembly that has been deployed to the GAC, you will need to browse to the \bin\Debug directory of the original project via the Browse tab of the Add Reference dialog in Visual Studio.

当您需要引用已部署到GAC的程序集时,您需要通过Visual Studio中“添加引用”对话框的“浏览”选项卡浏览到原始项目的\ bin \ Debug目录。

The reason this works is that since you've installed the assembly into the GAC, it will have a strong name and therefore a .publickey value in the manifest.

这样做的原因是,由于您已将程序集安装到GAC中,因此它将具有强名称,因此清单中具有.publickey值。

When you reference an assembly whose manifest contains a .publickey value, Visual Studio assumes the strongly named assembly will most likely be deployed to the GAC, and therefore does not bother to copy the binary to your application folder.

当您引用其清单包含.publickey值的程序集时,Visual Studio假定强名称程序集很可能会部署到GAC,因此无需将二进制文件复制到应用程序文件夹。

Instead, it will use the version in the GAC.

相反,它将使用GAC中的版本。

#3


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 hekps,

希望这个hekps,

Muse VSExtensions

#1


The add reference dialog actually looks at the registry, in particular:

添加引用对话框实际上是查看注册表,特别是:

  • [HKEY_LOCAL_MACHINE]\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders
  • [HKEY_CURRENT_USER]\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders

To add your assembly, you must edit these registry keys. Or simply using the "Browse..." button (instead) may be more tempting.

要添加程序集,必须编辑这些注册表项。或者只是使用“浏览...”按钮(而不是)可能更具吸引力。

#2


When you need to reference an assembly that has been deployed to the GAC, you will need to browse to the \bin\Debug directory of the original project via the Browse tab of the Add Reference dialog in Visual Studio.

当您需要引用已部署到GAC的程序集时,您需要通过Visual Studio中“添加引用”对话框的“浏览”选项卡浏览到原始项目的\ bin \ Debug目录。

The reason this works is that since you've installed the assembly into the GAC, it will have a strong name and therefore a .publickey value in the manifest.

这样做的原因是,由于您已将程序集安装到GAC中,因此它将具有强名称,因此清单中具有.publickey值。

When you reference an assembly whose manifest contains a .publickey value, Visual Studio assumes the strongly named assembly will most likely be deployed to the GAC, and therefore does not bother to copy the binary to your application folder.

当您引用其清单包含.publickey值的程序集时,Visual Studio假定强名称程序集很可能会部署到GAC,因此无需将二进制文件复制到应用程序文件夹。

Instead, it will use the version in the GAC.

相反,它将使用GAC中的版本。

#3


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 hekps,

希望这个hekps,

Muse VSExtensions