I am trying to build a collection of .vcxproj generated by Premake within VS Code. What I don’t get is why it works for executing the premake generation but not the .vcxproj builds as the old batch files are the same except they call msbuild.exe with a full path.
** 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.
This is my tasks.json there is more but it’s just rinse and repeat.
{
"version": "2.0.0",
"windows": {
"options": {
"shell": {
"executable": "cmd.exe",
"args": [
"/C",
// The path to VsDevCmd.bat depends on the version of Visual Studio you have installed.
""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
},
},
...
],
}
}
2
Answers
I managed to find a solution to this problem while trying to start a process in an external terminal. By replacing "command":"msbuild.exe" with "command":"cmd.exe" and moving the "msbuild.exe" into the argument list preceded by "/C" fixes the failing path string.
VS2019 is an inherited development tool, but VSCode is actually just an text editor.
If you want to use VSCode to build and run C++ code, you will need multiple extensions and configure everything by yourself.
Here is how I make it work:
1, install gcc and configure it to the environment variables of the system.
2, install C/C++, C/C++ Extension Pack, CMake, CMake Tools.
3, Close VSCode and reopen it, this step is to make sure the VSCode load the environment variables and extension features.
4, Write a CMakeLists.txt to activate the CMake extension:
This is my project structure(Created from Visual Studio):
When you configure the file and save, CMake extension should auto build the project.
If it didn’t build, just go this place and click the button:
After that, configure everything needed and click run:
5, Result:
This is my code(a console app):
For more details about more complicated situation, you can do a research on configurations in CMakeLists.txt.