在PowerShell中静默地将目录中的所有DLL注册到GAC中

3
我需要使用PowerShell静默地将一个目录中的所有.dll文件注册到GAC,而不会弹出任何屏幕弹窗。请问应该如何操作?
4个回答

6

我是PowerShell GAC的作者。使用PowerShell GAC,您无需使用gacutil,只需使用以下命令将文件夹中的所有dll安装到GAC中。

# Can only be run from an elevated prompt
Add-GacAssembly C:\Folder\*.dll

5
使用 gacutil.exe
& gacutil.exe -i <strongly named DLL>

注意 - DLL 必须符合可以安装到 GAC 的要求。

什么是强名称的 DLL。我可以通过单击 Gacutil 窗口中的安装按钮来安装它,但使用上述命令。 - user1595214
FYI,& 是不必要的。gacutil.exe 将被解析为命令而非字符串。 - Keith Hill
@user1595214 "<strongly named dll>" 只是一个占位符,用于指定您想要放置在 GAC 中的程序集路径。 - Keith Hill
仅在当前目录运行时才需要@KeithHill。我看到的大多数实例在其路径中具有空格,例如C:\ Program Files \ Microsoft SDKs \ Windows \ v7.0A \ bin \ gacutil.exe,因此要调用它说C的根,您需要&“ C:\ Program Files \ Microsoft SDKs \ Windows \ v7.0A \ bin \ gacutil.exe”。我通常也使用它,因为它适用于所有情况。 - Andy Arismendi
也许您还没有以管理员身份专门运行PowerShell? - Lars Truijens
显示剩余2条评论

3

.Net Framework已经包含了将组件注册到GAC的方法,无需添加SDK和第三方插件。

[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
$publisher = New-Object System.EnterpriseServices.Internal.Publish

# For installation 
$publisher.GacInstall("C:\Components\MyComponent.dll")

# For removal
$publisher.GacRemove("C:\Components\MyComponent.dll")

0
这是一个晚回答,但也许有人会觉得有用。假设已知 gacutil.exe 的路径,可以使用以下脚本:
Get-ChildItem "<full_path_to_your_directory>\*" -include "*.dll" | ForEach-Object -Process { gacutil -i $_.FullName }

<full_path_to_your_directory>应替换为所需目录的路径。末尾的"\*"是必需的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接