PS Core 7.3执行MSBUILD脚本遇MSB4184错误:是Bug还是可修复?
PowerShell Core 7.3下MSBuild编排脚本故障问题
我们用于构建/部署编排的PowerShell脚本仅在PS Core 7.3中出现故障,PS Core 7.2.x及Windows PowerShell 5.x(Windows 10)环境下均可正常运行。
触发的错误信息
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(321,5): error MSB4184: The expression "[System.IO.Path]::Combine(C:\Source\ourRepo\ourCSProj, bin\"AnyCPU\"\DevAzure\)" cannot be evaluated. Illegal characters in path. [C:\Source\ourRepo\ourCSProj\ourCSProj.csproj]
项目与执行命令详情
这是一个基于.NET Framework 4.8的WebAPI/类库项目,手动在命令行执行以下MSBuild命令可正常完成构建:
& "C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64\MSBuild.exe" ourCSProj\ourCSProj.csproj /p:Platform="AnyCPU" /t:Clean /nologo /p:Configuration=DevAzure /p:VisualStudioVersion=17.0 /v:m /p:SolutionDir=C:\Source\ourRepo\
脚本执行的差异问题
但通过PowerShell脚本构建命令并使用& "$cmd" $cmdArgs $msbuildBaseArgs语法执行时触发上述错误。其中:
$cmd为MSBuild.exe的完整路径$cmdArgs与$msbuildBaseArgs为数组形式的参数集合
报错相关的MSBuild目标代码
报错指向Microsoft.Common.CurrentVersion.targets文件第321行,代码内容如下:
<TargetDir Condition="'$(OutDir)' != ''">$([MSBuild]::Escape($([System.IO.Path]::GetFullPath(`$([System.IO.Path]::Combine(`$(MSBuildProjectDirectory)`, `$(OutDir)`))`))))</TargetDir>
核心疑问
- PS Core 7.3中发生了什么变更,导致
OutDir被解析为bin\"AnyCPU\"\DevAzure\(包含非法的转义引号字符)? - 为何PS Core 7.3会对
Platform参数的处理出现差异,进而引发该问题?
内容的提问来源于stack exchange,提问作者Howard Hoffman
相关产品推荐
相关产品推荐

