【问题标题】:Visual Studio Code: running preLaunchTask with multiple tasksVisual Studio Code:使用多个任务运行 preLaunchTask
【发布时间】:2019-01-07 00:10:48
【问题描述】:

我试图弄清楚如何在 launch.json 文件的 prelaunchtask 中一次运行多个任务。

我在tasks.json中的代码如下:

    "version": "2.0.0",
"tasks": [
    {
        "label": "CleanUp_Client",
        "type": "shell",
        "command": "rm",
        "args": [
            "-f",
            "Client"
        ],
    },
    {
        "label": "Client_Build",
        "type": "shell",
        "command": "g++",
        "args": [
            "-g",
            "client.cpp",
            "-o",
            "Client",
            "-lssl",
            "-lcrypto"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "problemMatcher": "$gcc"
    }
]

在preLaunchTask参数的launch.json中,如果我只把它工作的构建任务,但是我想运行多个任务,在这种情况下是CleanUp_Client和Client_Build。

我尝试添加另一个 preLaunchTask - 但是看起来您只能使用该参数一次,所以我尝试了:

"preLaunchTask": "build" + "clean", "preLaunchTask": "build"; "clean", "preLaunchTask": "build" & "clean", "preLaunchTask": "build" && "clean",

都没有成功,语法不正确。

另外,作为第二部分,我想知道这个组部分是如何工作的,以及它对“isDefault”意味着什么:true。

供您参考:https://code.visualstudio.com/docs/editor/tasks

【问题讨论】:

    标签: visual-studio-code vscode-settings vscode-tasks


    【解决方案1】:

    这是可行的。基本上,您创建另一个任务,其中包含您希望在 preLaunchTask 上使用 dependsOn 关键字运行的所有其他任务。

    参考代码:

        "tasks": [
        {
            "label": "CleanUp_Client",
            "type": "shell",
            "command": "rm",
            "args": [
                "-f",
                "Client"
            ]
        },
        {
            "label": "Client_Build",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g",
                "client.cpp",
                "-o",
                "Client",
                "-lssl",
                "-lcrypto"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": "$gcc"
        },
        {
            "label": "Build",
            "dependsOn": [
                "CleanUp_Client",
                "Client_Build"
            ]
        }
    ]
    

    在这种情况下,您可以将 preLaunchTask 设置为“Build”,它会同时运行这两个任务。

    我很好奇是否有其他人知道从 launch.json preLaunchTask 运行多个任务的替代方法或正确语法

    【讨论】:

    • 这仍然对您有用吗?我以这种方式配置了我的设置,但 vscode 调试器只是挂起。
    • 在代码 1.39.2 中,如果它们不是 build 类型,我可以将多个任务链接在一起。如果所有build 任务都包含在列表中,则它们都会失败。这看起来像一个 Visual Studio Code 错误。
    猜你喜欢
    • 2015-10-20
    • 2018-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-10
    • 2020-01-21
    • 1970-01-01
    相关资源
    最近更新 更多