Steps to Reproduce:
create launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}\\src\\FrontEnd\\build",
"preLaunchTask": "core"
}
]
}
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "core",
"type": "npm",
"script": "start",
"path": "src/FrontEnd/core/",
"isBackground": true,
"dependsOn":["loss"],
"problemMatcher":{
"owner": "custom",
"pattern":[
{
"regexp": "something not exists",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"activeOnStart": true,
"beginsPattern": "[email protected] start",
"endsPattern": "created ..\\\\build\\\\vendor.js"
}
}
},
{
"label": "loss",
"type": "npm",
"script": "watch",
"path": "src/FrontEnd/loss/",
"isBackground": true,
"problemMatcher":{
"owner": "custom",
"pattern":[
{
"regexp": "something not exists",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"activeOnStart": true,
"beginsPattern": "[email protected] start",
"endsPattern": "waiting for changes"
}
}
}
]
}
I can use beginsPattern/endsPattern with no issue if I direct launched by preLaunchTask, but if I have DependsOn for same task, it will run the dependencies but can't detect it's status by using endsPattern, the task will hang there. it looks like a bug for me.
I tried to use the new Terminal: "terminal.integrated.windowsEnableConpty": false/true, no difference.
I tried to use presentation.panel:"dedicated", no difference.
I think we have done a nice work on putting tasks running in background and launch, but not those tasks in DependsOn property.
Does this issue occur when all extensions are disabled?: Yes
(Experimental duplicate detection)
Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:
no,
(Experimental duplicate detection)
Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:
no not a duplicate.
As far as I can tell, there's currently no way to support a task that runs multiple watch tasks at the same time. I wasted several hours yesterday trying to get this to work. Am I wrong?
@StephenWeatherford what is supported is having one main task that starts n other tasks that run in watch mode. Something like:
{
"label": "watch",
"dependsOn": [
"watch:types",
"watch:jsonrpc",
"watch:protocol",
"watch:server",
"watch:client"
],
"problemMatcher": []
}
were watch:* tasks are all background tasks.
What doesn't work right now is to serialize background tasks. They reason is that is it not clear to define when a background task is in a state that it depending task can start.
I also wasted a few hours trying to automate a docker compose to run before running my server. They work independently, but I can't depend on one with another, it just won't advance to the next task even though the problemMatcher/endsPattern matches.
@AlexAegis Are you on Windows and if so, what version? And what version of VS Code? There were some terminal/OS problems that were making it so lines wrapped unexpectedly in the terminal and problem matchers would become unreliable.
Yes I'm on Windows 10 version 1903 build no 18362.295, and 1.37.1 (User) of VS Code. I haven't changed any terminal settings, the default plain PowerShell. I also tried .* as the endsPattern.
Can you share your task and your problem matcher?
I'm having this problem too:
// tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Jester Web",
"type": "npm",
"script": "jester-web",
"problemMatcher": [],
"isBackground": true,
"dependsOn": ["UVP Web"],
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "dedicated",
"showReuseMessage": true,
"clear": true,
"group": "Dev Servers"
}
},
{
"label": "UVP Web",
"type": "npm",
"script": "web",
"isBackground": true,
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "dedicated",
"showReuseMessage": true,
"clear": true,
"group": "Dev Servers"
},
"problemMatcher": {
"pattern":{
"regexp": "whatever",
"file": 1,
"location": 2,
"message": 3,
},
"background": {
"activeOnStart": true,
"beginsPattern": "Starting 'buildWebappEsm'",
"endsPattern": "Starting 'devWatch'"
}
}
},
}
}
And this is the UVP Web task's log output (note that I had to kill the watching task for the right pane to start):

Starting 'devWatch' is not being picked up and allowing the Jester Web task to start. I had to manually kill the left pane task before the right one would start.
Have tried multiple iterations of configuring the "watch" command, all which run but prevent the debug from continuing. Only works if the watch command is the only task defined in preLaunchTask.
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Flutter",
"request": "launch",
"type": "dart",
"flutterMode": "debug",
"postDebugTask": "cleanup",
// Doesnt work
"preLaunchTask": "build",
// Works! but doesnt allow for multiple tasks
"preLaunchTask": "flutter: build_runner watch"
}
]
}
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "cleanup",
"command": "echo ${input:terminate}",
"type": "shell"
},
{
"label": "build:graphql",
"command": "graphql get-schema -e development",
"type": "shell"
},
// This gives same result
// {
// "label": "build:flutter",
// "command": "watch",
// "type": "flutter",
// "isBackground": true,
// "problemMatcher": ["$dart-pub-build_runner"]
// },
{
"label": "build",
// Both tasks run, but debug doesnt start (tried multiple variations)
"dependsOn": ["build:graphql", "flutter: build_runner watch"],
"dependsOrder": "sequence"
}
],
"inputs": [
{
"id": "terminate",
"type": "command",
"command": "workbench.action.tasks.terminate",
"args": "terminateAll"
}
]
}
@alexr00
I got the same issue as the first post with the most recent version of Vscode
Here my launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Chrome",
"type": "chrome",
"request": "launch",
"preLaunchTask": "start-all",
//If i put: "preLaunchTask": "Start httpserver", chrome will launch after launching http-server.
"url": "http://localhost:4200/#",
"webRoot": "${workspaceFolder}",
"sourceMapPathOverrides": {
"webpack:/*": "${webRoot}/*",
"/./*": "${webRoot}/*",
"/src/*": "${webRoot}/*",
"/*": "*",
"/./~/*": "${webRoot}/node_modules/*"
},
"internalConsoleOptions": "neverOpen"
},
}
and here my tasks.json:
{
"version": "2.0.0",
"tasks": [
{
//"type": "npm",
//"script": "start-httpserver",
"type": "shell",
"command": "node node_modules/http-server/bin/http-server ./dist/PublishDir -p 4000 --cors",
"isBackground": true,
"label": "Start httpserver",
"presentation": {
"reveal": "always",
"focus": false,
"panel": "new",
"showReuseMessage": true,
"clear": false,
"group": "A"
},
"problemMatcher": {
"owner": "http-server",
"pattern": [
{
"regexp": ".",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"activeOnStart": true,
"beginsPattern": ".",
"endsPattern": "."
}
}
},
{
"type": "npm",
"script": "start",
//npm start = ng serve
"label": "Start App",
"isBackground": true,
"presentation": {
"focus": true,
"reveal": "always",
"panel": "new",
"group": "A"
},
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": {
"owner": "typescript",
"source": "ts",
"applyTo": "closedDocuments",
"fileLocation": [
"relative",
"${cwd}"
],
"pattern": "$tsc",
"background": {
"activeOnStart": true,
"beginsPattern": {
"regexp": "(.*?)"
},
"endsPattern": {
"regexp": "Compiled |Failed to compile."
},
}
}
},
{
"label": "start-all",
"dependsOrder": "parallel",
"dependsOn": [
"Start httpserver", "Start App"
]
}
]
}
Here what i got on the terminals:

So if on preLaunchTask, i set one of the task, chrome will launch, but if i use the task using "dependsOn", it won't start chrome except if i kill the http-server and my "Start App" task (ng serve on my package,json). Even if on "dependsOn" i only put 1 task (i.e.: Start httpserver), It won't work.
I tried multiple vscode version as i believed it works before
https://stackoverflow.com/questions/44242048/how-to-make-vscode-not-wait-for-finishing-a-prelaunchtask#comment105938297_54017304
I still have the same issue. I spent a bunch of days with multiple syntax, solution, stackoverflow, this github issues list. I don't find any solution so i guess it's really a bug behaviour using "dependsOn".
It is not similar to this issue #92792
because on his example, the 2 tasks are not background tasks but simple ping which will stop after 2 - 12 pings as defined on his package.json
In the meantime, I will try npm-run-all module but it will be great to make it work natively with vscode.
Thanks
@StephenWeatherford what is supported is having one main task that starts n other tasks that run in watch mode. Something like:
{ "label": "watch", "dependsOn": [ "watch:types", "watch:jsonrpc", "watch:protocol", "watch:server", "watch:client" ], "problemMatcher": [] }were
watch:*tasks are all background tasks.What doesn't work right now is to serialize background tasks. They reason is that is it not clear to define when a background task is in a state that it depending task can start.
@dbaeumer The vscode docs say that the background tasks need problemMatchers that tracks when they are "done":
https://code.visualstudio.com/Docs/editor/tasks#_compound-tasks

But I cannot get the "One" task to actually start, if task "Two" or "Three" is a watch task, even if I have a problemMatcher that catches when the watch task has finished recompiling.
It just sits there, waiting, until I manually kill the watch task, then the "One" task will do its thing.
Thanks, that may work for me, will give it a try.
I created a basic repo that shows the issue of not being able to create a task that depends on a background/watch task:
https://github.com/penx/vscode-task-dependson
In this project:
As per @linusbrolin's comment above, the documentation says that this should work:
Any background/watch tasks used in dependsOn with "dependsOrder": "sequence" must have a problem matcher that tracks when they are "done"
... so please can you either mark this ticket as a bug or else update the documentation to make it clear this is not supported?
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Node",
"type": "node",
"request": "launch",
"program": "${file}",
"preLaunchTask": "Two"
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "One",
"type": "shell",
"command": "echo start1",
"dependsOrder": "sequence",
"dependsOn": ["Two", "Three"],
"problemMatcher": []
},
{
"label": "Two",
"type": "shell",
"isBackground": true,
"command": "echo start2 && echo end2 && read varname",
"problemMatcher": {
"owner": "custom",
"pattern": {
"regexp": "^$"
},
"background": {
"activeOnStart": true,
"beginsPattern": "start2",
"endsPattern": "end2"
}
}
},
{
"label": "Three",
"type": "shell",
"command": "echo start3"
}
]
}
Just chipping in here that I also found this problem and it would be super amazing if it was made to work.
We appear to be running into this as well in vscode-dapr when layering use of Dapr tasks on top of Azure Functions tasks, both of which are background tasks with begin/end patterns. I'm not able to make the Dapr task wait for the Azure Function task (as a dependsOn) as VS Code doesn't seem to recognize when the Azure Functions task completes.
@penx thanks for the simple repro repository.
Until now, you could have background tasks in dependsOn, but since those background tasks never "finish", you couldn't sequence anything off of them.
I have pushed a small change that _does_ allow some sequencing. You can have background tasks in dependsOn _and_ they can be sequenced. However any errors that those background tasks produce will not prevent subsequent tasks from executing. I will leave this issue open to track supporting that.
@alexr00 how can we specify a background task in a good state for its dependent tasks to kick in? For me, I want to start a sync task that will take some time to sync my files and then outputs "sync is completed, now watching for file changes...". I want to start my dependent tasks to start when that output is printed.
@mohsen1 I would expect that the task runner would detect the endsPattern of the first task, and then start the next one.
https://code.visualstudio.com/docs/editor/tasks#_background-watching-tasks
@mohsen1 @tetchel in my mind, I planned on having an endsPattern detect when a service is finished running through it's initial setup. Like when the watcher is running, or files are being served and are ready to be accessed, that would be matched for my endsPattern. I don't really care about exits on those tasks unless I'm killing my services.
It is an interesting question. With a background task, beginsPattern and endsPattern are somewhat overloaded with the concept of something like "begin background task" and "end background task" (e.g. "files changed", "compilation complete", respectively).
However it probably makes sense to differentiate between "begin task" and "end task" and "begin service" and "end service" in this context. Perhaps a better solution would be to add two new keys to the background task configuration to reflect these two different contexts.
I don't think all that additional complexity is going to add anything if we
can do what we want with the options we have now.
Most helpful comment
@penx thanks for the simple repro repository.
Until now, you could have background tasks in
dependsOn, but since those background tasks never "finish", you couldn't sequence anything off of them.I have pushed a small change that _does_ allow some sequencing. You can have background tasks in
dependsOn_and_ they can be sequenced. However any errors that those background tasks produce will not prevent subsequent tasks from executing. I will leave this issue open to track supporting that.