How to run several tasks in VSCode
Asked Answered
S

2

7

I am trying to migrate to VSCode and having a problem with setting-up tasks. It is easy to define tasks in tasks.json but I would like to run several tasks simultaneously (which I can't).

Here is my use-case: I have two watchers in my project (one for gulp and another one for webpack). Plus I want to be able to run webpack task separately. When I run one of the watchers I cannot run anything else - VSCode requires me to terminate the running task at first.

In Visual Studio I used Task Runner where several tasks were running simultaneously. Is it possible to achieve the same in VSCode?

Sidneysidoma answered 9/4, 2017 at 16:15 Comment(1)
See Also: Multiple commands/tasks with Visual Studio CodeThant
C
4

Using compound tasks, you can specify dependsOn and dependsOrder on a separate task, and run them in parallel like this:

{
  "label": "start-tasks",
  "dependsOrder": "parallel",
  "dependsOn": [
      "taskOne",
      "taskTwo"
  ]
}
Chatterjee answered 9/7, 2019 at 4:37 Comment(0)
E
0

The problem is that "Run Test Task" and "Run Build Task" do not execute all tasks in that specific group. Usually you get a drop down selection so you can choose which task to execute. Since you have specified one of the tasks as default, the selection will be skipped and instead the default task is executed.

You can work around that by adding dependencies. Take the following example:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Echo 1",
            "command": "echo",
            "type": "shell",
            "args": [ "echo1" ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "dependsOn":["Echo 2"]
        },
        {
            "label": "Echo 2",
            "type": "shell",
            "command": "echo",
            "args": [ "echo2" ],
            "group": "build"
        }
    ]
}
Esteresterase answered 25/5, 2021 at 17:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.