在PowerShell中使用带有空格的文件路径运行cmd /c

5
我正在尝试在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"

这会产生错误。
'C:\Program' is not recognized as an internal or external command. 

我的路径中有空格,我要运行几个通过“&&”分隔的命令,这让一切都变得混乱了。我已经尝试在各处加上引号,但还是无法使其正常工作。

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

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

它可以正常工作。但是我无法使其他命令也正常工作。

1个回答

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

如果可以的话,您应该将您的答案标记为此问题的答案,以便它不会被留作“未回答”。 - Adam Parsons
1
@AdamParsons 当我尝试时,会收到一条消息,说我必须等到明天才能操作。所以我会在明天再试。 - gynetik

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接