powershell - 该字符串缺少终止符:'。在WindowsServerCore容器中

标签 powershell docker

我在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/

相关文章:

azure - 术语 'az' 未被识别为 cmdlet、函数、脚本文件或可操作程序的名称

mysql - 将SQL查询结果存储在变量中

java - 将命令行参数传递给在 Docker 中运行的 Java 应用程序 (Spring Boot)

java - 从昨天起就无法在 Dockerfile 上运行 Java

powershell - 将 Powershell 核心设置为 windows/linux 上的默认 GNU Make shell

regex - 在Powershell中替换文本 block

Azure Powershell - 用于跨订阅获取 VM 信息的脚本

oracle - 登录sqlplus,执行dockerfile中的sql文件

docker - sudo docker build -t =“nisevi/static_web”无法正常工作

linux - 如何将左三角形 (<) 作为别名命令的一部分包含在内?