Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code: running preLaunchTask with multiple tasks

Tags:

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

like image 293
Revx0r Avatar asked Jul 30 '18 17:07

Revx0r


People also ask

How do I run multiple tasks in Vscode?

Note that the definition is a list, so more than one task can be specified. In that case the tasks are executed in parallel. In your case adding "dependsOn":["Compile/minify cms. scss"] to your main build task should execute both tasks.

How do I run a build task in Vscode?

Tip: You can run your task through Quick Open (Ctrl+P) by typing 'task', Space and the command name.

How do you run in debug mode in Visual Studio code?

To bring up the Run and Debug view, select the Run and Debug icon in the Activity Bar on the side of VS Code. You can also use the keyboard shortcut Ctrl+Shift+D. The Run and Debug view displays all information related to running and debugging and has a top bar with debugging commands and configuration settings.

Where Is tasks json in Vscode?

json file (located under your workspace . vscode folder) if you want to do more than simply run the task. For example, you might want to match reported problems and highlight them within VS Code, or to trigger a build task using the Run Build Task command ( kb(workbench.


1 Answers

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

like image 109
Revx0r Avatar answered Oct 20 '22 01:10

Revx0r