在GAC中注册DLL(CMD或PowerShell) [英] Register DLL in GAC (CMD or PowerShell)
问题描述
我正在尝试在 GAC
中注册一个 .DLL
.目前,我无法证明已将其添加到程序集中.
I'm trying to register a .DLL
in the GAC
.
Currently I'm having trouble to prove it has been added to the assembly.
使用命令
C:\ Windows \ System32>%programfiles(x86)%\ MicrosoftSDKs \ Windows \ v7.0A \ Bin \ gacutil.exe -i"path \ to \ my \ file.dll"
C:\Windows\System32>%programfiles(x86)%\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe -i "path\to\my\file.dll"
提示符告诉我程序集已添加到缓存中.
The prompt tells me that the assembly has been added to the cache.
进行检查时
C:\ Program Files(x86)\ Microsoft SDKs \ Windows \ v7.0A \ Bin> gacutil.exe -l file.dll
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin>gacutil.exe -l file.dll
它表示程序集中有0个元素.
It says that there are 0 elements in the assembly.
通过 Powershell
命令,我正在尝试添加 DLL
,如下所示:
Via Powershell
commands, I'm trying to add the DLL
like this:
PS C:\ WINDOWS \ system32>添加类型-AssemblyName"System.EnterpriseServices"
PS C:\WINDOWS\system32> Add-Type -AssemblyName "System.EnterpriseServices"
PS C:\ WINDOWS \ system32> $ publish =新对象System.EnterpriseServices.Internal.Publish
PS C:\WINDOWS\system32> $publish = New-Object System.EnterpriseServices.Internal.Publish
PS C:\ WINDOWS \ system32> $ publish.GacInstall("file.dll")
PS C:\WINDOWS\system32> $publish.GacInstall("file.dll")
我做错了什么?如何将 .DLL
添加到 GAC
中?(对我而言)最好的方法是使用 Powershell
.
What did I do wrong? How can I add the .DLL
to the GAC
? The best way (for me) would be doing that with Powershell
.
推荐答案
请记住以管理员身份运行PowerShell,否则将无法正常工作.
Remember to run PowerShell as administrator or this won't work.
$dllpath = c:\path\yourdll.dll
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
$publish = New-Object System.EnterpriseServices.Internal.Publish
$publish.GacInstall($dllpath)
此后,您可能需要重新启动任何相关的服务或程序,例如:
You will likely need to restart whatever related service or program after this, for example:
if (Get-Service "YourService" -ErrorAction SilentlyContinue)
{
Stop-Service -Name 'YourService'
Start-Service -Name 'YourService'
}
或者只是重新启动计算机.
Or just restart your computer.
这篇关于在GAC中注册DLL(CMD或PowerShell)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!