gpt4 book ai didi

json - 配置 Visual Studio Code 任务以顺序执行多个 shell 命令

转载 作者:行者123 更新时间:2023-12-05 02:05:46 24 4
gpt4 key购买 nike

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

我在 Ubuntu 18.04 LTS 上使用 Visual Studio Code。

这是我当前如何将构建任务的命令链接到 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"
}

关于json - 配置 Visual Studio Code 任务以顺序执行多个 shell 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63142061/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com