Reputation: 2115
I would like to configure one task labeled "Build and then Run" that would execute a specific build task and then run the executable. I thought that the dependsOn
property was what I was looking for but as it turns out it runs the tasks in parallel instead.
Here is an example of tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": "g++ -g ${workspaceFolder}/main.cpp -o ${workspaceFolder}/main.exe",
"problemMatcher": "$gcc"
},
{
"label": "Run",
"type": "shell",
"command": "${workspaceFolder}/main.exe"
},
{
"label": "Build and then Run",
"type": "shell",
"dependsOn": [ // <------ important
"Run",
"Build"
]
}
]
}
It doesn't matter in what order I put the tasks into the dependsOn
array. The "Run" task executes with error because the "Build" task creates the executable too late.
Is there some property or trick that allows two tasks to run in sequence?
Upvotes: 2
Views: 2623
Reputation: 182771
{
"label": "Build and then Run",
"type": "shell",
"dependsOrder": "sequence", <= `parallel must be the default
"dependsOn": [
"Run",
"Build"
]
}
If you specify "dependsOrder": "sequence" then your task dependencies are executed in the order they are listed in dependsOn. Any background/watch tasks used in dependsOn with "dependsOrder": "sequence" must have a problem matcher that tracks when they are "done".
That implies to me, plus your experience, that omittiing the option dependsOn
means by default the tasks will run in parallel, not in sequence.
Upvotes: 4