华域联盟 PowerShell PowerShell中使用.NET将程序集加入全局程序集缓存

PowerShell中使用.NET将程序集加入全局程序集缓存

通常情况下,将程序集(Assembly)加入全局程序集缓存(GAC,Global Assembly Cache),可以使用GacUtil工具。只要使用/i参数,就可以把指定路径的程序集添加进GAC了。

不过由于GacUtil并不是.Net Framework的一部分,而是和Windows SDK一起发布的,这就导致了机器中安装了.Net,却可能找不到GacUtil的情况。

在PowerShell中,我们可以直接使用.Net的类库来搞定这件事,而不需要通过GacUtil。具体代码如下:

[Reflection.Assembly]::LoadWithPartialName("System.EnterpriseServices") > $null
[System.EnterpriseServices.Internal.Publish] $publish =
 New-Object System.EnterpriseServices.Internal.Publish
$publish.GacInstall("<DLL的完整路径>")

另外,System.EnterpriseServices.Internal.Publish还提供了类似RegAsm的功能,具体可以查询MSDN。

您可能感兴趣的文章:

本文由 华域联盟 原创撰写:华域联盟 » PowerShell中使用.NET将程序集加入全局程序集缓存

转载请保留出处和原文链接:https://www.cnhackhy.com/15125.htm

本文来自网络,不代表华域联盟立场,转载请注明出处。

作者: sterben

发表回复

联系我们

联系我们

2551209778

在线咨询: QQ交谈

邮箱: [email protected]

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部