Visual Studio Code: running preLaunchTask with multiple tasks

Revx0r picture Revx0r · Jul 30, 2018 · Viewed 13.8k times · Source

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

Answer

Revx0r picture Revx0r · Jul 30, 2018

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