在 GAC 中注册 DLL(CMD 或 PowerShell)

Tim*_* D. 3 windows dll powershell gac

我正在尝试.DLLGAC. 目前我无法证明它已添加到程序集中。

使用命令

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 = 新对象 System.EnterpriseServices.Internal.Publish

PS C:\WINDOWS\system32> $publish.GacInstall("file.dll")

我做错了什么?我怎样才能将.DLL加到GAC?最好的方法(对我来说)是用Powershell.

coi*_*ird 8

请记住以管理员身份运行 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)
Run Code Online (Sandbox Code Playgroud)

在此之后,您可能需要重新启动任何相关的服务或程序,例如:

if (Get-Service "YourService" -ErrorAction SilentlyContinue)
    {
        Stop-Service -Name 'YourService' 
        Start-Service -Name 'YourService' 

    }
Run Code Online (Sandbox Code Playgroud)

或者只是重新启动计算机。