我正在尝试在 GAC
中注册一个 .DLL
。
目前我无法证明它已添加到程序集中。
使用命令
C:\Windows\System32>%programfiles(x86)%\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe -i "path\to\my\file.dll"
提示告诉我程序集已添加到缓存中。
检查时
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin>gacutil.exe -l file.dll
它说程序集中有 0 个元素。
通过 Powershell
命令,我尝试像这样添加 DLL
:
PS C:\WINDOWS\system32> Add-Type -AssemblyName "System.EnterpriseServices"
PS C:\WINDOWS\system32> $publish = New-Object System.EnterpriseServices.Internal.Publish
PS C:\WINDOWS\system32> $publish.GacInstall("file.dll")
我做错了什么?如何将 .DLL
添加到 GAC
?最好的方法(对我来说)是使用 Powershell
来做到这一点。
最佳答案
请记住以管理员身份运行 PowerShell,否则这将不起作用。
$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)
在此之后您可能需要重新启动任何相关服务或程序,例如:
if (Get-Service "YourService" -ErrorAction SilentlyContinue)
{
Stop-Service -Name 'YourService'
Start-Service -Name 'YourService'
}
或者只是重新启动计算机。
关于windows - 在 GAC 中注册 DLL(CMD 或 PowerShell),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45593418/