首页 > 解决方案 > 如何在 VScode 中多次调用任务

问题描述

任务.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build OpenGL project",
            "type": "shell",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "command": "make",
            "presentation": {
                "reveal": "never",
                "clear": true,
                "echo": false
            },
        },
        {
            "label": "postdebugKill",
            "type": "process",
            "command":[
                "${command:workbench.action.terminal.kill}",
                "${command:workbench.action.acceptSelectedQuickOpenItem}",
            ],
        },
        {
            "label": "Build & run OpenGL project",
            "type": "shell",
            "group": {
                "kind": "test",
                "isDefault": true
            },
            "command": "make",
            "args": [
                "run"
            ],
            "presentation": {
                "reveal": "never",
                "clear": true,
                "echo": false
            },
        },
        {
            "label": "Terminate All Tasks",
            "command": "echo ${input:terminate}",
            "type": "shell",
            "problemMatcher": []
        }
    ],
    "inputs": [
        {
            "id": "terminate",
            "type": "command",
            "command": "workbench.action.terminal.kill",
            "args": "terminateAll"
        },
    ]
}

启动.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "OpenGL",
            "type": "lldb",
            "request": "launch",
            "program": "${workspaceFolder}/bin/app",
            "preLaunchTask": "Build OpenGL project",
            "postDebugTask": "postdebugKill",
            "console": "externalTerminal",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "MIMode": "lldb",
        }
    ]
}

在 Tasks.json 文件中,我有一个 postdebugKill 任务,它会在调试我的 C++ 项目时杀死打开的终端实例,但是如何在 postDebugTask 中调用该任务 2 次,以便关闭打开的 2 个终端实例。

当我在 vscode 中启动 CPP 调试器时,它会打开两个终端选项卡,那么如何多次调用 postdebugKill 来终止多个终端实例。

标签: visual-studio-code

解决方案


推荐阅读