我在Windowsservercore:10.0.14393.206镜像中运行脚本时遇到问题,该镜像用于构建.NET项目。我需要使用Powershell脚本手动将某些.dll文件的位置从软件包更改为Web / Bin,但出现错误:
The string is missing the terminator: '.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx
ception
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
脚本如下:
$srcdir = "packages";
$destdir = "Web\Bin";
md $destdir;
$files = (Get-ChildItem $srcdir -Recurse -Include *.dll*, *.lic*);
$files|foreach($_){
echo $_.Fullname;
Copy-Item -Path $_.Fullname -Destination ("$destdir" + "\" + "$_.Name") -Recurse;
}
有什么想法吗?
最佳答案
您在这里遇到了一些问题。首先,使用Join-Path构建路径比尝试自行构建路径要好得多。其次,在构建路径时,无需在任何变量周围加上双引号。第三,如果要使用不需要的双引号,则需要在$ _。Name周围使用$()来强制访问属性,而不是对象的.TOString()函数。这是执行该行的另一种方法:
Copy-Item -Path $_.Fullname -Destination (Join-Path $destdir $_.Name) -Recurse;
关于powershell - 该字符串缺少终止符:'。在WindowsServerCore容器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49616313/