34

I am trying to figure out how to run multiple tasks at once in the prelaunchtask of the launch.json file.

My code in the tasks.json is as follows:

    "version": "2.0.0",
"tasks": [
    {
        "label": "CleanUp_Client",
        "type": "shell",
        "command": "rm",
        "args": [
            "-f",
            "Client"
        ],
    },
    {
        "label": "Client_Build",
        "type": "shell",
        "command": "g++",
        "args": [
            "-g",
            "client.cpp",
            "-o",
            "Client",
            "-lssl",
            "-lcrypto"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "problemMatcher": "$gcc"
    }
]

In the launch.json for the preLaunchTask parameter if I only put the build task it works, however I want to run multiple tasks, in this case is the CleanUp_Client and Client_Build.

I tried adding another preLaunchTask - However it looks like you can only use that parameter once, so then I tried:

"preLaunchTask": "build" + "clean", "preLaunchTask": "build"; "clean", "preLaunchTask": "build" & "clean", "preLaunchTask": "build" && "clean",

All with no success, not the correct syntax.

Also as a second part to this I would like to know how the group part of this works, and what it means for "isDefault": true.

For your reference: https://code.visualstudio.com/docs/editor/tasks

Lennart
  • 9,657
  • 16
  • 68
  • 84
Rev
  • 1,213
  • 2
  • 11
  • 17

2 Answers2

47

Here is something that will work. Basically you make another task in which you include all the other tasks that you want to run on your preLaunchTask with the dependsOn keyword.

Code for reference:

    "tasks": [
    {
        "label": "CleanUp_Client",
        "type": "shell",
        "command": "rm",
        "args": [
            "-f",
            "Client"
        ]
    },
    {
        "label": "Client_Build",
        "type": "shell",
        "command": "g++",
        "args": [
            "-g",
            "client.cpp",
            "-o",
            "Client",
            "-lssl",
            "-lcrypto"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "problemMatcher": "$gcc"
    },
    {
        "label": "Build",
        "dependsOn": [
            "CleanUp_Client",
            "Client_Build"
        ]
    }
]

In this case you would set your preLaunchTask to "Build" and it will run both tasks.

I am curious if anybody else knows an alternative or the correct syntax to just run several tasks from the launch.json preLaunchTask

Rev
  • 1,213
  • 2
  • 11
  • 17
  • 2
    Is this still working for you? I configured my setup this way but the vscode debugger just hangs. – ponytailPalm May 14 '19 at 14:07
  • In Code 1.39.2, I am able to link together multiple tasks provided they are not of the `build` type. All `build` tasks fail if they are included in a list. This looks like a Visual Studio Code bug. – AlainD Nov 09 '19 at 13:59
4

I agree with @Revx0r answer, but there is important notice: you need to add to last task dependsOrder field, if you want to run it in sequence:

{
    "label": "Build",
    "dependsOrder": "sequence",
    "dependsOn": [
        "CleanUp_Client",
        "Client_Build"
    ]
}
Ilya Sh
  • 41
  • 2