我试图弄清楚如何在launch.json文件的预启动任务中一次运行多个任务。
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。
答案 0 :(得分:7)
这是行得通的。基本上,您执行另一个任务,其中您要使用dependsOn
关键字包含要在preLaunchTask上运行的所有其他任务。
参考代码:
"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运行几个任务