Powershell 字符串缺少终止符:';。WindowsServerCore容器内部

Powershell 字符串缺少终止符:';。WindowsServerCore容器内部,powershell,docker,Powershell,Docker,在用于构建.NET项目的windowsservercore:10.0.14393.206映像中运行脚本时出现问题。我需要使用Powershell脚本手动将某些.dll文件的位置从package更改为Web/Bin,但出现错误: The string is missing the terminator: '. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx ception +

在用于构建.NET项目的windowsservercore:10.0.14393.206映像中运行脚本时出现问题。我需要使用Powershell脚本手动将某些.dll文件的位置从package更改为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;
}

对此有什么想法吗?

这里有一些问题。首先,使用连接路径来构建路径要比尝试自己构建路径好得多。其次,在构建路径时,不需要在任何变量周围加双引号。第三,如果要使用不必要的双引号,则需要在$\名称周围使用$()来强制访问属性,而不是对象的.TOString()函数。下面是另一种实现这一点的方法:

Copy-Item -Path $_.Fullname -Destination (Join-Path $destdir $_.Name) -Recurse;

非常好的推荐,但是我仍然有同样的问题,如果这样做的话,我会怀疑代码中有打字错误。这就是你的全部代码吗?事实上,这就是失败的代码块,当我删除这段代码时,其余的代码都能正常工作。嗯……我没有看到问题所在。如果以后有机会,我将尝试模拟一个测试环境并复制该问题。是的,请尝试在windowsservercore:10.0.14393.206容器中进行。