0

是否可以从 VSCode 中的任务运行任务?

示例 json:

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
    {
        "taskName": "Show In Chrome",
        "windows": {
            "command": "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
        },
        "osx": {
            "command": "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
        },
        "args": [
            "${file}"
        ],
        "type": "process",
    },
    {
        "taskName": "Show Coverage",
        // this is the task to call another task
    }
]

}

我想做的是让 Show Coverage 任务在 coverage 文件夹中查找文件,然后调用 Show In Chrome 任务将其显示为正在传递的文件的参数。这可能吗?

4

1 回答 1

0

事实证明,文档网站上的当前配置没有针对任务进行更新。

但是,如果您希望一个任务调用其他任务,因为它依赖于它们,您可以简单地添加此配置

    {
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
    {
        "taskName": "Show In Chrome",
        "identifier": "showInChrome",
        "windows": {
            "command": "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
        },
        "osx": {
            "command": "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
        },
        "args": [
            "${file}"
        ],
        "type": "process",
    },
    {
        "taskName": "Show Coverage",
        "dependsOn": "showInChrome"
    }
]
}

这将导致任务运行前一个任务,然后运行它设置的任何命令。

注意:您可以通过使用标识符数组来使用多个依赖项。

于 2017-09-05T17:26:11.573 回答