How to make the launch task wait for a Visual Studio Code msbuild prelaunchTask?

Viewed 296

I have a Visual Studio 2019 project which I want to compile and debug (or rather launch the MSBuild compiler as a launch task from within VS Code) with Visual Studio Code instead. This does work partially for me with the following configuration files:

launch.json:

{
   "version": "0.2.0",
   "configurations": [
       {
           "name": "(Windows) Launch",
           "type": "cppvsdbg",
           "request": "launch",
           "program": "x64/Debug/foo.exe",
           "args": [],
           "stopAtEntry": true,
           "cwd": "E:/path/to/project/solution",
           "environment": [],
           "console": "externalTerminal",
           "prelaunchTask": "msbuild"
       }
   ]
}

tasks.json:

{
   "version": "2.0.0",
   "tasks": [
      {
         "label": "msbuild",
         "type": "shell",
         "command": "msbuild",
         "isBackground": false,
         "args": [
             // Ask msbuild to generate full paths for file names.
             "/property:GenerateFullPaths=true",
             "/property:Configuration=Debug",
             "/property:Platform=x64",
             "/t:build"
         ],
         "group": "build",
         "presentation": {
             // Reveal the output only if unrecognized errors occur.
             //"reveal": "silent"
             "revealProblems": "always",
             "reveal": "always"
         },
         // Use the standard MS compiler pattern to detect errors, warnings and infos
         "problemMatcher": "$msCompile"
     }
   
   ]
}

For some reason, the launch task doesn't wait for the pre-launch task.

However, if I first run the msbuild task manually (it compiles as expected) and then run the debugging task with "prelaunchTask": "msbuild" commented-out, the debugger works as expected (i.e. I can step through the code, use breakpoints, etc. ).

Side note: On the internet, I saw people having the exact opposite problem: they were doing web development and had the problem that the pre-launch task and the build task were waiting on each other. This is why I have set "isBackground": false.

1 Answers

According to the documentation:

https://code.visualstudio.com/docs/editor/tasks#_background-watching-tasks

you should use "beginsPattern" and "endsPattern" in your tasks.json

in my case (using VITE for svelte):

enter image description here

I told when "VITE v" is printed in terminal it means the beginning of task is started and when "127.0.0.1:5173" is printed it means the task is completed successfully, then VS Code will run chrome and etc. in your case, you must find your pattern for "msbuild".

P.S. "isBackground": false does not work for me, so I think you should not use it.

Related