VS Code构建Premake生成的.vcxproj项目失败问题求助
问题解决:VS Code中构建Premake生成的VCXPROJ项目失败
问题情况
在VS Code中构建Premake生成的.vcxproj项目时,Premake的项目生成操作可正常执行,但.vcxproj构建失败。旧批处理文件仅需使用msbuild.exe的完整路径即可正常运行,当前执行构建任务时出现如下错误:
'C:/Program' is not recognized as an internal or external command, operable program or batch file.
终端进程以退出代码1终止,相关终端输出如下:
--- ** Visual Studio 2019 Developer Command Prompt v16.11.17 ** Copyright (c) 2021 Microsoft Corporation --- Building configurations... Running action 'vs2019'... Done (160ms). - Terminal will be reused by tasks, press any key to close it. - Executing task: msbuild.exe SimClient.vcxproj && "/p:configuration=Debug Static" && /p:platform=x64 ***'C:/Program' is not recognized as an internal or external command, operable program or batch file.*** - The terminal process "cmd.exe /C "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/Tools/VsDevCmd.bat" && msbuild.exe SimClient.vcxproj && "/p:configuration=Debug Static" && /p:platform=x64" terminated with exit code: 1. - Terminal will be reused by tasks, press any key to close it.
错误原因分析
当前tasks.json存在两处关键问题:
- 全局shell配置中,将
"&&"作为单独参数传递给cmd.exe,导致VsDevCmd.bat的路径空格未被正确解析,触发C:/Program的路径截断错误。 - Build任务的
args数组中错误地将&&作为msbuild的参数,实际上&&是cmd的命令分隔符,不应作为msbuild的参数传递;同时msbuild的配置参数(如/p:configuration)需要直接作为命令参数,无需用&&分隔。
修正后的tasks.json配置
{ "version": "2.0.0", "windows": { "options": { "shell": { "executable": "cmd.exe", "args": [ "/C", // 将VsDevCmd.bat调用和后续命令的连接逻辑整合到一个参数中 "\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/Tools/VsDevCmd.bat\" &&" ] } } }, "tasks": [ { "type": "shell", "label": "Generate Project", "command": "${workspaceFolder}/packages/premake/premake5.exe", "args": ["vs2019"], "group": { "kind": "build", "isDefault": true } }, { "type": "shell", "label": "Build SimClient (Debug)", "dependsOn": ["Generate Project"], "command": "msbuild.exe", "args": [ "SimClient.vcxproj", "/p:configuration=Debug Static", "/p:platform=x64" ], "problemMatcher": ["$msCompile"], "group": { "kind": "build", "isDefault": true } } ] }
额外说明
如果仍然存在msbuild路径识别问题,可以直接指定msbuild的完整路径作为command值,例如:
"command": "\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe\""
内容的提问来源于stack exchange,提问作者Dan Ashby
相关产品推荐
相关产品推荐

