My VSCode project is multi-root workspace. That is I have multiple workspaces each in separate directories, each has a .vscode folder.
I'm trying to build a workspace with dependencies between each module via build tasks.
I've tried to set dependsOn parameter for a task, but it yields a following error:
Couldn't resolve dependent task 'build FOO' in workspace folder 'BAR'
(here BAR build task depends on FOO)
Is there a better/correct/any way to achieve my goal?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With