我需要使用PowerShell静默地将一个目录中的所有.dll文件注册到GAC,而不会弹出任何屏幕弹窗。请问应该如何操作?
我是PowerShell GAC的作者。使用PowerShell GAC,您无需使用gacutil,只需使用以下命令将文件夹中的所有dll安装到GAC中。
# Can only be run from an elevated prompt
Add-GacAssembly C:\Folder\*.dll
.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")
Get-ChildItem "<full_path_to_your_directory>\*" -include "*.dll" | ForEach-Object -Process { gacutil -i $_.FullName }
<full_path_to_your_directory>应替换为所需目录的路径。末尾的"\*"是必需的。
&
是不必要的。gacutil.exe
将被解析为命令而非字符串。 - Keith HillC:\ Program Files \ Microsoft SDKs \ Windows \ v7.0A \ bin \ gacutil.exe
,因此要调用它说C的根,您需要&“ C:\ Program Files \ Microsoft SDKs \ Windows \ v7.0A \ bin \ gacutil.exe”
。我通常也使用它,因为它适用于所有情况。 - Andy Arismendi