0

I have several projects in my workspace which I would like to start automatically in VS Code via task.

The structure is:

project1/folder1/folder2/ docker compose start
project1/folder1/folder3/ docker compose start 

project2/folder4/ docker start

project 3 ng serve

at best also ng lint in Project 3.

In project 4 there are already launch tasks. These should also start automatically

I've already read up a bit on the topic and am trying my hand at the first tasks.json.

My problem at the moment is that I can not get into the subfolder and can not rundocker compose start. Also I don't know how to include the launch task.

The automatic start when opening VS Code works already once.

starball
  • 20,030
  • 7
  • 43
  • 238

1 Answers1

0

You can make multiple individual tasks where you specify the and then use the Compound Tasks feature.

In each task, specify the current working directory using the options > cwd field. Using the ${workspaceFolder} variable will probably be useful. Just for example (you might write your task with a different approach- Ex. using the "shell" type):

"label": "Docker Folder 2",
"type": "process",
"command": "docker",
"args": ["compose", "start"],
"options": {
   "cwd": "${workspaceFolder}/project1/folder1/folder2/"
}

Then your compound task might look something like this (you can use the runOptions > runOn field to make the task run when the workspace folder opens):

"label": "Docker",
"dependsOn": [
   "Docker: Project 1, Folder 2",
   "Docker: Project 1, Folder 3",
   "Docker: Project 2, Folder 4",
   "Docker: Project 3",
],
"runOptions": {
   "runOn": "folderOpen"
}
starball
  • 20,030
  • 7
  • 43
  • 238
  • Thank you very much. That works. How can I add the task from the launch.json? –  May 05 '23 at 11:38
  • @Ludo google "`vscode run task from launch.json`" -> https://stackoverflow.com/q/43836861/11107541 – starball May 05 '23 at 22:37
  • No, I need it the other way around. I need an automatically starting task to start a run and debug session. With your suggestion I have to start the entry in the launch.json manually and then get a task executed automatically. But I want to automate the manual part. –  May 11 '23 at 13:45
  • ... I told you how to do exactly what you _wrote_ asking to do. So you asked wrong I suppose? If you want to run a task on startup, I already showed you how to do that. See the part of my answer that has "`runOn`". – starball May 11 '23 at 19:01
  • RunOptions Arena not allowed in launch.json –  May 12 '23 at 05:12
  • @Ludo I have no idea what this "RunOptions Arena" is that you're talking about. can you refer me to something that explains it? – starball May 12 '23 at 05:28
  • RunOptions are not allowed in launch.json. This is what i mean. –  May 15 '23 at 12:28
  • nowhere did I say to try putting runOptions in a launch.json. read what I linked you to. focus on the part that says `preLaunchTask`. – starball May 15 '23 at 16:59
  • But that's the wrong direction. So I have to start the launch task manually again. I want it to be available as a task. So he would restart the docker container when starting the launch task manually –  May 16 '23 at 17:55
  • @Ludo what exactly do you want to be available as a task and what as a launch config? I find your wording quite confusing. – starball May 16 '23 at 18:05
  • I would like to start an entry in launch.json (whatever you call it now) via a task in Tasks.json. This gives me the opportunity to do this when starting vscode. –  May 17 '23 at 11:38
  • @Ludo that's a different question. write a new question post. I'm pretty sure the answer is no. – starball May 17 '23 at 15:45