Visual Studio Code: running preLaunchTask with multiple tasks

19,389

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

Share:
19,389

Related videos on Youtube

Revx0r
Author by

Revx0r

Security Software Engineer with interests in reverse engineering, security research and penetration testing. I like to play with 1s & 0s ^ 0s & 1s =)

Updated on March 11, 2021

Comments

  • Revx0r
    Revx0r about 3 years

    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

  • ponytailPalm
    ponytailPalm almost 5 years
    Is this still working for you? I configured my setup this way but the vscode debugger just hangs.
  • AlainD
    AlainD over 4 years
    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.