如何在其他任务中运行两个已定义的任务

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

我在tasks.json中定义了很多任务

{
  "version": "2.0.0",
  "tasks": [
    {   "identifier": "tsc-main", 
        "type": "typescript",
        "tsconfig": "tsconfig.json",
        "problemMatcher": [
            "$tsc"
        ]
    },
    {   "identifier": "tsc-other", 
        "type": "typescript",
        "tsconfig": "./other-path/tsconfig.json",
        "problemMatcher": [
            "$tsc"
        ]
    }
  ]
}

我想要一个可以同时运行多个任务的任务。如果其他有错误,请运行所有操作而不停止。

就像是:

{   "identifier": "joined task", 
    "type": "task-list",  // <= does not exists
    "tasks": ["tsc-main","tsc-other"] // <== 
}

其他方式是在shell中运行所有命令,但我不知道如何通过命令行运行任务

{   "identifier": "joined task", 
    "type": "shell",
    "command": "task tsc-main ; task tsc-other", // <== I don't know how to write "task"
    "problemMatcher": [
            "$tsc"
    ]
}

我也知道如何在shell任务中编写命令列表,但那还有另一个问题:定义写在两个不同的位置(原始任务和连接任务),这违反了规则“每个定义必须只在一个地方”。如果团队中的某个人为一个任务添加了一个选项,他必须记住在“加入的任务”中添加选项。

{   "identifier": "joined task", 
    "type": "shell",
    "command": "tsc ; tsc -p ./other-path/tsconfig.json", 
    "problemMatcher": [
        "$tsc" // <= I am not shure about this
    ]
}
typescript visual-studio-code tsc vscode-tasks
1个回答
2
投票

我想你正在寻找dependsOn

{
    "label": "joined task",
    "dependsOn": ["tsc-main", "tsc-other"]
}
© www.soinside.com 2019 - 2024. All rights reserved.