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

问题描述 投票:4回答:1

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

{
    "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→Run Task逐个启动它们(所以我需要发出两次序列,每次执行一次)我最终会同时运行两个任务。

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

visual-studio-code vscode-tasks
1个回答
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"
}
© www.soinside.com 2019 - 2024. All rights reserved.