You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让PowerShell正确传递含空格的MSBuild参数?

PowerShell调用MSBuild的参数传递问题

给定配置

$msbuild = 'c:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\MSBuild.exe'
$props = 'Prop1=value1;Prop2="value 2"'

期望执行的命令

希望实际执行的命令为:

"c:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\MSBuild.exe" /p:Prop1=value1;Prop2="value 2"

尝试的方法及问题

尝试了最直接的调用方式:

& $msbuild /p:$props

但执行后生成的命令不符合预期,实际结果类似:

"c:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\MSBuild.exe" "/p:Prop1=value1;Prop2=\"value 2\""

当前可行的解决办法

目前找到的唯一有效方案是回退到PowerShell旧版的参数解析行为:

$PSNativeCommandArgumentPassing = 'Legacy'

除了这种方式,还有其他更优的解决办法吗?


内容的提问来源于stack exchange,提问作者Alex I

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 12:54:55