You can have a tasks
section in your .code-workspace
file. There you can create a task like "Build all" and define dependsOn
tasks. However, there you also cannot reference build tasks from the workspace folders (to me this sounds like a reasonable feature and I believe they should implement it at some time).
My workaround is to copy the relevant build task from the sub-tasks files into the .code-workspace
file and reference them in my "Build all" task.
Example .code-workspace
:
{
"folders": [
{
"path": "proj-A"
},
{
"path": "proj-B"
}
],
"tasks": {
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "Build A",
"command": "make",
"args": ["-j4"],
"options": {
"cwd": "${workspaceFolder}/../proj-A",
},
"problemMatcher": [
"$gcc"
],
"group": "build",
},
{
"type": "shell",
"label": "Build B",
"command": "make",
"args": ["-j4"],
"options": {
"cwd": "${workspaceFolder}/../proj-B",
},
"problemMatcher": [
"$gcc"
],
"group": "build",
},
{
"type": "shell",
"label": "Build all",
"command": "echo",
"args": ["Building everything"],
"options": {},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"dependsOrder":"sequence",
"dependsOn": ["Build A", "Build B"]
},
]
}
}
Note the cwd
option in the individual build tasks. ${workspaceFolder}
seems to be set to the first path in the "folders"
section. You could also set cwd
to absolute paths.
This is a bit hacky and the fact that one has to copy the build tasks is not beautiful, but it works for now and it can be easily adapted once it is possible to reference tasks of sub-tasks files.