VSCode make launch configuration fail if preLaunchTask fails

I have a launch configuration that runs a bat script as a pre launch task. Sometimes, the bat script fails to build my project. However, the debugging task still runs, which is really annoying, and means I have to keep an eagle eye on the output of the terminal before it changes to the debug console.

How can I prevent the launch configuration from continuing if the pre launch task fails?


I had the same problem with a cmake task.
I've solved it by changing task's type to shell and passing everything else in command field.

Now when the task fails with an error (exit code != 0), it stops and does not launch the application.


launch.json:

{
   ...
   "name": "(gdb) Launch",
   "type": "cppdbg",
   "request": "launch",
   "preLaunchTask": "CMake Build"     // <--- task name
   ...
}

tasks.json:

...
{
    "label": "CMake Build",
    "command": "/usr/bin/cmake --build /{project_directory}/build --config Debug --target all -j 14 -- ",
    "type": "shell",                // <--- changed this part
    "group": "build"
}
...

Cheers