Man*_*ous 4 shell json cmake visual-studio-code vscode-tasks
是否有可能使用单独的参数和选项将多个 shell 命令按顺序添加到 Visual Studio Code 任务?我设法使用&&将 then 链接到单个命令来执行多个命令,就像在任何 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"
}
Run Code Online (Sandbox Code Playgroud)
更新: - - - - - - - - - - - - - - - - - - - - - - - - -------------------
我尝试使用该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"
}
Run Code Online (Sandbox Code Playgroud)
Man*_*ous 10
感谢许多评论,我找到了一个通过将“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"
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4455 次 |
| 最近记录: |