从 PowerShell 运行 cmd /c,文件路径中包含空格

gyn*_*tik 5 powershell cmd

我正在尝试在 PowerShell 中运行以下命令

PS C:\Users\Administrator> cmd /c "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\vsdevcmd.bat && nuget restore && msbuild mywebapp.sln /p:DeployOnBuild=true /p:PublishedProfile=ServerFolderProfile"
Run Code Online (Sandbox Code Playgroud)

这会产生错误

'C:\Program' is not recognized as an internal or external command. 
Run Code Online (Sandbox Code Playgroud)

我的路径有空格,我正在运行几个由 && 分隔的命令,这把一切搞乱了。我尝试过在各处添加引号,但无法使其正常工作。

如果我只运行命令的第一部分

cmd /c "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\vsdevcmd.bat"
Run Code Online (Sandbox Code Playgroud)

效果很好。但我也无法让其他命令工作。

gyn*_*tik 5

根据文档cmd.exe

如果指定了/C/K,则命令行的其余部分将在新 shell 中作为立即命令进行处理。多个命令由命令分隔符分隔&,或者&&如果用引号括起来则被接受

所以我只需将命令更改为:

PS C:\Users\Administrator> cmd /c "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\vsdevcmd.bat" "&&" nuget restore "&&" msbuild mywebapp.sln /p:DeployOnBuild=true /p:PublishedProfile=ServerFolderProfile
Run Code Online (Sandbox Code Playgroud)