I've started using Visual Studio Code (version 1.83.1) few days ago, and I want to run C++ files by MSVC compiler without using "Developer Command Prompt for VS 2022" every time. And I want to know how can I modify tasks.json file for this purpose, because it's the only way I know to do it.
I used the instructions from here:
https://code.visualstudio.com/docs/cpp/config-msvc#_run-vs-code-outside-the-developer-command-prompt
Tried every variant from here:
How to configure the VS Code shell like the developer command prompt?
Nothing helps, task file works without errors, but when I try to run .cpp file it gives an error:
cl.exe build and debug is only usable when VS Code is run from the Developer Command Prompt for VS.
My VsDevCmd.bat file is placed where it should be: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools And when I run that Developer Command Prompt for VS 2022 manually everything works fine, but if I try to do it using tasks.json it fails.
At the moment my tasks.json file looks like this:
{
"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": "process",
"label": "cl.exe build active file",
"command": "cl.exe",
"args": [
"&",
"/Zi",
"/EHsc",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}"
],
"problemMatcher": ["$msCompile"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}