【问题标题】:How to run several tasks as a group?如何将多个任务作为一个组运行?
【发布时间】:2017-08-03 13:49:15
【问题描述】:

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

{
    "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】:

    您可以使用"dependsOn" 属性。如果要先运行"build site" 任务,请将其添加为"serve site" 任务的"dependsOn"。如果您希望两者一起运行,请创建另一个同时依赖于 "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"
    }
    

    更新:这是新的 tasks.json 模板 (v2.0.0) 的 link to the documentation。与此问题相关的部分是taskName 已重命名为label,但dependsOn 的值保持不变。

    【讨论】:

    • 谢谢,但这不起作用,因为“构建站点”是一项不会结束的任务。这两个任务实际上并没有结束,必须并行运行。
    • 可能想要查看 vscode 的任务后台选项。我没用过,所以不知道有什么限制。 code.visualstudio.com/docs/editor/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-23
    • 2016-10-02
    • 2014-06-21
    • 2021-08-14
    • 2021-06-14
    相关资源
    最近更新 更多