我的要求是在GAC中注册dll,我正在使用gacutil。我写的coe如下。
function RegisterAssembliesToGAC([string]$frameworkPath,[string]$GACDllLocation)
{
try
{
$Dirs = Get-ChildItem $GACDllLocation -Recurse
$Dlls = $Dirs | Where { $_.extension -eq ".dll" }
ForEach($dll in $Dlls)
{
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\gacutil.exe -i $dll.FullName
}
}
catch [Exception]
{
write-host $_.Exception.Message `n;
}
}
这对我来说很好。现在我如图所示 $frameworkpath 是一个参数,我想将它的值作为参数传递。所以我修改了我的代码如下
function RegisterAssembliesToGAC([string]$frameworkPath,[string]$GACDllLocation)
{
try
{
$Dirs = Get-ChildItem $GACDllLocation -Recurse
$Dlls = $Dirs | Where { $_.extension -eq ".dll" }
ForEach($dll in $Dlls)
{
$frameworkPath="C:\Windows\Microsoft.NET\Framework64\v4.0.30319"
$gacpath=[string]$frameworkPath + "\gacutil.exe"
Invoke-Expression "$gacpath -i $dll.FullName"
}
}
catch [Exception]
{
write-host $_.Exception.Message `n;
}
}
这给出了一个错误:将程序集添加到缓存失败:文件名、目录名或卷标语法不正确。试了很多次,无法修复。请帮忙 :)