Rev
Rev

Reputation: 1433

Visual Studio Code: running preLaunchTask with multiple tasks

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

Upvotes: 43

Views: 36470

Answers (2)

Ilya Sh
Ilya Sh

Reputation: 91

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"
    ]
}

Upvotes: 9

Rev
Rev

Reputation: 1433

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

Upvotes: 60

Related Questions