C# 如何在 GAC 中注册 .NET DLL 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2182316/
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
How do I register a .NET DLL file in the GAC?
提问by Vineet
I have made a .NET .DLL
file, which I want to register in the GAC.
我制作了一个 .NET.DLL
文件,我想在GAC 中注册它。
I have used this command in Windows Server 2003Command Prompt:
我在Windows Server 2003命令提示符中使用过这个命令:
C:\"Path of dll"\>gacutil /i dllname.dll
'gacutil' is not recognized as an internal or external command,
operable program or batch file.
It says the path is not correct.
它说路径不正确。
Do I need to use this in a .NET cmd prompt? If it is that, I am not able to locate the .NET cmd prompt.
我需要在 .NET cmd 提示符下使用它吗?如果是这样,我将无法找到 .NET cmd 提示符。
回答by Ando
Just drag and drop the DLL file into folder C:\Windows\assembly
using Windows Explorer.
只需C:\Windows\assembly
使用 Windows 资源管理器将 DLL 文件拖放到文件夹中即可。
Caveat:
警告:
In earlier versions of the .NET Framework, the Shfusion.dll Windows shell extension let you install assemblies by dragging them to File Explorer. Beginning with .NET Framework 4, Shfusion.dll is obsolete.
在 .NET Framework 的早期版本中,Shfusion.dll Windows shell 扩展允许您通过将程序集拖动到文件资源管理器来安装程序集。从 .NET Framework 4 开始,Shfusion.dll 已过时。
Source: How to: Install an assembly into the global assembly cache
回答by abmv
回答by Fredrik M?rk
You can do that using the gacutil
tool. In its simplest form:
您可以使用该gacutil
工具执行此操作。以其最简单的形式:
gacutil /i yourdll.dll
You find the Visual Studio Command Prompt in the start menu under Programs-> Visual Studio-> Visual Studio Tools.
您可以在Programs-> Visual Studio-> Visual Studio Tools下的开始菜单中找到 Visual Studio 命令提示符。
回答by tbischel
gacutil.exeis the .NET utility used to work with the GAC.
gacutil.exe是用于处理GAC的 .NET 实用程序。
One can check the availability of a shared assembly in GACby using the command:
可以使用以下命令检查GAC 中共享程序集的可用性:
gacutil.exe /l "assemblyName"
One can register a shared assembly in the GACby using the command:
可以使用以下命令在GAC 中注册共享程序集:
gacutil.exe /i "assemblyName"
Or by dropping an assembly file into the following location using the GUI:
或者通过使用 GUI 将程序集文件拖放到以下位置:
%windir%\assembly\
Other options for this utility will be briefly described if you use the /?
flag, that is:
如果您使用该/?
标志,将简要描述此实用程序的其他选项,即:
gacutil.exe /?
回答by user264138
As ando said, just drag and drop the assembly to the C:\windows\assembly folder. It works.
正如安藤所说,只需将程序集拖放到 C:\windows\assembly 文件夹即可。有用。
回答by Rubens Farias
You'll need:
你需要:
- Strong name your assembly (Visual Studio, Project Properties, Signing tab, Sign the assembly)
- Alter your Build Events (Project Properties, Build Events tab, Post-build command line)
- 强命名您的程序集(Visual Studio、项目属性、签名选项卡、签名程序集)
- 更改构建事件(项目属性、构建事件选项卡、构建后命令行)
cd C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin gacutil.exe /i "$(TargetPath)" /f /nologo gacutil /l "$(TargetName)" /nologo
Now, everytime you build your project, it'll be installed on GAC.
现在,每次构建项目时,它都会安装在 GAC 上。
回答by Tom
These responses don't tell you that gacutil resides in C:\WINDOWS\Microsoft.NET\Framework\v1.1* by the way.
顺便说一下,这些响应并没有告诉您 gacutil 驻留在 C:\WINDOWS\Microsoft.NET\Framework\v1.1* 中。
I didn't have it in my v2.0 folder. But I tried dragging & dropping the DLL into the C:\WINDOWS\Assembly folder as was suggested here earlier and that was easier and does work, as long as it's a .NET library. I also tried a COM library and this failed with an error that it was expecting an assembly manifest. I know that wasn't the question here, but thought I'd mention that in case someone finds out they can't add it, that that might be why.
我的 v2.0 文件夹中没有它。但是我尝试将 DLL 拖放到 C:\WINDOWS\Assembly 文件夹中,正如前面所建议的那样,只要它是 .NET 库,就更容易并且确实有效。我还尝试了一个 COM 库,但失败了,错误是它需要一个程序集清单。我知道这不是这里的问题,但我想我会提到,以防有人发现他们无法添加它,这可能就是原因。
-Tom
-汤姆
回答by BelgiumHorse
Run Developer Command Prompt For V2012 or any version installed in your system
gacutil /i pathofDll
Enter
运行 V2012 或系统中安装的任何版本的 Developer Command Prompt
gacutil /i pathofDll
进入
Done!!!
完毕!!!
回答by vamsee
The above solutions look marvelous. However, to be simple, all you need I guess is to enter the assembly name along with its full path like:
上述解决方案看起来很棒。但是,简单来说,我猜您只需要输入程序集名称及其完整路径,例如:
gacutil -i C:\MyDlls\GacDeployedAssemblies\dllname.dll
Paying attention to C:\MyDlls\GacDeployedAssemblies
注意C:\MyDlls\GacDeployedAssemblies
回答by Kailash Dhaker
In case on windows 7 gacutil.exe (to put assembly in GAC) and sn.exe(To ensure uniqueness of assembly) resides at C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin
如果在 Windows 7 gacutil.exe(将程序集放入 GAC)和 sn.exe(以确保程序集的唯一性)驻留在 C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin
Then go to the path of gacutil as shown below execute the below command after replacing path of your assembly
然后转到如下所示的 gacutil 路径,在替换程序集路径后执行以下命令
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin>gacutil /i "replace with path of your assembly to be put into GAC"
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin>gacutil /i“替换为要放入 GAC 的程序集路径”