如何作为一个组运行多个任务?

时间:2017-08-03 13:49:16

标签: visual-studio-code vscode-tasks

我创建了两个任务来帮助我开发一个网站:

{
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "build site",
            "command": "jekyll b --watch --incremental",
            "type": "shell",
            "group": "build"
        },
        {
            "taskName": "serve site",
            "command": "./_devd -ol _site",
            "type": "shell",
            "group": "build"
        }
    ]
}

我可以用 F1 →运行任务逐个启动它们(所以我需要发出两次序列,每次执行一次),最后我会同时运行两个任务。

是否可以自动执行此操作并同时运行一组任务? I thought group条目会将它们组合在一起,但它是不是这种情况(它们只是被认为属于buildtest组 - 而且我没有找到一种方法可以立即启动整个组。)

1 个答案:

答案 0 :(得分:8)

您可以使用"dependsOn"属性。如果您想先运行"build site"任务,请将其添加为"dependsOn"任务的"serve site"。如果您希望两者一起运行,请执行另一项取决于"build site""serve site"任务的任务。

以下是在提供网站之前构建网站的示例:

{
  "taskName": "build site",
  "command": "jekyll b --watch --incremental",
  "type": "shell",
  "group": "build"
},
{
  "taskName": "serve site",
  "command": "./_devd -ol _site",
  "type": "shell",
  "group": "build",
  "dependsOn": "build site" // <--- Added this
},

对于长时间运行的任务,不知道更简洁的方法,但......

以下是同时运行这两个任务的示例:

{
  "taskName": "Run Everything", // <-- Bind this task to a key
  "dependsOn": [ "build site", "serve site" ]
},
{
  "taskName": "build site",
  "command": "jekyll b --watch --incremental",
  "type": "shell"
},
{
  "taskName": "serve site",
  "command": "./_devd -ol _site",
  "type": "shell"
}