配置 Visual Studio 代码任务以顺序执行多个 shell 命令

Configure Visual Studio Code task to execute multiple shell commands in sequence

是否有可能将多个 shell 命令按顺序添加到具有单独参数和选项的 Visual Studio 代码任务?我设法使用 && 执行多个命令,然后将它们链接到一个命令,就像在任何 Linux shell 中一样。但我想,必须有更好的方法来做到这一点。

我在 Ubuntu 18.04 LTS 上使用 Visual Studio 代码。

这是我目前如何将构建任务的命令链接到 task.json 文件中以使用 cmake 构建 C++ 项目的示例:

{
    "tasks": [
        {
            "type": "shell",
            "label": "build",
            "command": "cd ${workspaceFolder}/build && cmake .. && make clean && make",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ],
    "version": "2.0.0"
}

更新:------------------------------------ ----------------------------

我尝试使用 dependsOn: 属性 来启动 4 个单独定义的任务。但是,这导致所有 4 个命令在不同的 shell 实例中同时执行,而不是按需要按顺序执行:

{
    "tasks": [
        {
            "type": "shell",
            "label": "build project",
            "dependsOn": [
                "Go to build folder",
                "Cmake",
                "make clean",
                "make",
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "label": "Go to build folder",
            "type": "shell",
            "command": "cd ${workspaceFolder}/build",
            "presentation": {
                "group": "cmake-complile"
            }
        },
        {
            "label": "Cmake",
            "type": "shell",
            "command": "cmake ..",
            "presentation": {
                "group": "cmake-complile"
            }
        },
        {
            "label": "make clean",
            "type": "shell",
            "command": "make clean",
            "presentation": {
                "group": "cmake-complile"
            }
        },
        {
            "label": "make",
            "type": "shell",
            "command": "make",
            "presentation": {
                "group": "cmake-complile"
            }
        }
    ],
    "version": "2.0.0"
}

感谢许多评论,我找到了一个将“dependsOrder”设置为“sequence”的解决方案:

{
    "tasks": [
        {
            "type": "shell",
            "label": "build project",
            "dependsOrder": "sequence",
            "dependsOn": [
                "Cmake",
                "make clean",
                "make",
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "label": "Cmake",
            "type": "shell",
            "command": "cmake ..",
            "options": {
                "cwd": "${workspaceFolder}/build",
            },
        },
        {
            "label": "make clean",
            "type": "shell",
            "command": "make clean",
            "options": {
                "cwd": "${workspaceFolder}/build",
            },
        },
        {
            "label": "make",
            "type": "shell",
            "command": "make",
            "options": {
                "cwd": "${workspaceFolder}/build",
            },
        }
    ],
    "version": "2.0.0"
}