Using. NET in PowerShell to add an assembly to the Global Assembly Cache
Generally, the Assembly is added to the Global Assembly Cache (GAC, Global Assembly Cache). You can use the GacUtil tool. You only need to use the/I parameter to add the assembly in the specified path to GAC.
However, GacUtil is not part of the. Net Framework, but released together with the Windows SDK. This causes. Net to be installed on the machine, but GacUtil may not be found.
In PowerShell, we can directly use the. Net class library to solve this problem, instead of using GacUtil. The Code is as follows:
1 2 3 4 |
[Reflection. Assembly]: LoadWithPartialName ("System. EnterpriseServices")> $ null [System. kerberiseservices. Internal. Publish] $ publish = New-Object System. kerberiseservices. Internal. Publish $ Publish. GacInstall ("<DLL full path> ") |
In addition, System. EnterpriseServices. Internal. Publish also provides functions similar to RegAsm. You can query MSDN for details.