-
Notifications
You must be signed in to change notification settings - Fork 29.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot define multiple commands in tasks.json #981
Comments
Let me suggest a simple example to implementation (tasks.json) ....
AND CTRL+SHIFT+B:
|
Hi, I need the feature too 👍 But, priority is low. Because, we can multiple command with the trick: http://qiita.com/usagi/items/5a0f4edc99420173abb3 ( Sorry, its wrote in Japanese. ) The abstract of the trick are:
Example { "version": "0.1.0"
, "command": "sh"
, "isShellCommand": true
, "showOutput": "always"
, "args": [ "-c" ]
, "tasks":
[ { "taskName": "la"
, "suppressTaskName": true
, "args": [ "\"ls -la\"" ]
}
, { "taskName": "hoge"
, "suppressTaskName": true
, "args": [ "\"echo hoge\"" ]
}
, { "taskName": "build"
, "suppressTaskName": true
, "args": [ "\"mkdir -k build; cd build; cmake ..; make\"" ]
}
, { "taskName": "debug"
, "suppressTaskName": true
, "args": [ "\"cd build; gdb bin/my-executable\"" ]
}
]
} Its can run in the current release version ( 0.10.3 ). 🐰 |
Nice @usagi , this is my solution:
tip: cmd for windows, sh for linux shortcut: (override default build command)
when i hit ctrl+shift+b, subtasks show up: Bonus: you can define your own shortcut:
|
This is very important. Say I want a test command and a build command. The test command needs to run The workaround is nice, but it is not cross-platform and quotes have to be escaped. {
"linux": {
"command": "sh",
"args": ["-c"]
},
"osx": {
"command": "sh",
"args": ["-c"]
},
"windows": {
"command": "powershell",
"args": ["-Command"]
}
} and then duplicate the tasks property for every single OS :/ |
@felixfbecker It's nice follow-up 👍 We can use |
Another plus one - and in my case, I can't use the workaround since I need a per OS switch and I can't rely on sh or cmd. |
@cfjedimaster Why can't you use the workaround exactly? |
Because my top level command would be start on Windows and open on OSX. So I can't use just cmd or just start and pass different args. |
@cfjedimaster You mean like this? {
"version": "0.1.0",
"isShellCommand": true,
"osx": {
"command": "sh",
"args": ["-c"],
"tasks": [
{"name": "run", "args": ["open mysuperawesomefile.txt"]}
]
},
"windows": {
"command": "cmd",
"args": ["/C"],
"tasks": [
{"name": "run", "args": ["start mysuperawesomefile.txt"]}
]
}
} |
Yes. But to be clear, I wouldn't want to replicate all the tasks for both. Basically, I want to be able to do N tasks per file as the original requestor suggested. For me, 9 of the 10 tasks I want can all be in one definition. One of them is different though and needs to do X for Windows and Y for OSX. |
Yeah I know it is a lot of code duplication, which is why they should really implement this feature. But for the time being, it's what works. |
@danielschmitz From your example, only the first taskName runs when I press Ctrl+Shift+B. I don't get presented with a list as in your screenshot.
|
Sorry @danielschmitz I misread your comment on adding |
@bbenoist I set up my VS Code tasks to use my Gruntfile.js tasks. I simply hit F1 and enter
|
@brennanMKE Thanks for the info but I needed to call different executables for different tasks. See @danielschmitz's example implementation for a practical example. #981 (comment) @danielschmitz @usagi @felixfbecker @cfjedimaster @csholmq Thanks everyone for the feedback and suggestions! FYI, I ended up using Jake to define all my tasks and pushed my concept up to calling a First here is a bit of context about the app I wanted to configure VS Code for:
My custom
Unfortunately, I cannot share my work for now because I need a special agreement for this. However, I can show you an example of a JSON configuration which would be compatible with the system I described: {
"defaultConfig": "ubuntu-debug",
"problemMatchers": {
"gcc": {
"owner": "gcc",
"fileLocation": [ "relative", "${workspaceRoot}" ],
"pattern": {
"regexp": "^(${sourceDir}\\/)?(.*):(\\d+):\\d+:\\s+(warning|error):\\s+(.*)$",
"file": 2, "line": 3, "severity": 4, "message": 5
}
},
"gfortran": {
"owner": "gfortran",
"fileLocation": [ "relative", "${workspaceRoot}" ],
"pattern": [
{
"regexp": "^(${sourceDir}\\/)?(.*):(\\d+)\\.\\d+:\\s*$",
"file": 2, "line": 3
},
{
"regexp": "^\\s*(.*)$",
"code": 1
},
{ "regexp": "^.*$" },
{
"regexp": "(Error|Warning):\\s*(.*)$",
"severity": 1, "message": 2, "loop": true
}
]
}
},
"configs": {
"local": {
"enabled": false,
"sourceDir": "${workspaceRoot}",
"cpus": 8,
"problemMatchers": [ "$msCompile" ]
},
"vagrant": {
"enabled": false,
"useVagrant": true,
"sourceDir": "/src",
"cpus": 1,
"problemMatchers": [ "gcc", "gfortran" ]
},
"debug": {
"enabled": false,
"cmake": { "buildType": "Debug" }
},
"release": {
"enabled": false,
"cmake": { "buildType": "Release" }
},
"ubuntu-debug": {
"enabled": true,
"buildDir": "/home/vagrant/build-debug",
"parents": [ "vagrant", "debug" ]
},
"ubuntu-release": {
"enabled": true,
"buildDir": "/home/vagrant/build-release",
"parents": [ "vagrant", "release" ]
},
"local-debug": {
"enabled": true,
"build-dir": "${workspaceRoot}/build-debug",
"parents": [ "local", "debug" ]
},
"local-release": {
"enabled": true,
"build-dir": "${workspaceRoot}/build-release",
"parents": [ "local", "release" ]
}
}
} Alternatives which would provide all the capabilities listed below in a simpler configuration file are welcome 😃 |
Not 100% related but interested people can take a look at the new Shell extension I made. It's able to run shell commands directly from the editor 🚀 |
I think the schema in this request could solve the problem: #4475 It allows to define multiple commands and it is very easy to transform to the current tasks.json schema. |
Problem solved, my |
@psulek Great catch! I'm glad you let me know ... I have an extension that doesn't support this now, but my users might be demanding that I do support it later. |
is there a way to make the tasks running one after the other? this will build the client \and server build in parallel and the last build will hide the first build result ("press a key to continue"). I created a meta task for test that call all the test tasks on the dotnet projects I need. But the first runs are hidden by the last one until you press enter. |
@Jonathan34 I'm sorry. That's not supported by the extension. That's a new feature for VSC, and I haven't had a chance to look at it. |
@Jonathan34 yes there is: The dependsOn works like dependent task in any other task runner (for example like gulp). If you want to depend the client build on the server build do: {
"version": "2.0.0",
"tasks": [
{
"taskName": "Client Build",
"command": "gulp",
"dependsOn": "Server Build",
"args": ["build"],
"isShellCommand": true,
"options": {
"cwd": "${workspaceRoot}/client"
}
},
{
"taskName": "Server Build",
"command": "gulp",
"args": ["build"],
"isShellCommand": true,
"options": {
"cwd": "${workspaceRoot}/server"
}
}
]
} This will execute them in sequence. |
@dbaeumer As this is true you cant use it like this: You need to do it this way (in current implementation): And you need to run |
@psulek agree in our scenario. But the client server build example had an artificial Build task which didn't run a command. Therefore I removed it and made client build depend on server build. So if you want to run two tasks in parallel you need a artificial task (without a command) to describe this. If you want to run two task in sequence you don't need and artificial task. |
@dbaeumer @psulek that should work i will try! thanks I have another problem with this: Could it be that upgrading the tasks,json to v2.0.0 while having a launch,json at version 0.2.0 creates some incompatibilities? launch.json
tasks.json
|
This is definitely a bug with task version 2.0.0. See #22250 |
Workaround is to empty the preLaunchTask value to "" and build manually before running the tests. |
Team, Just started using vscode and couldn't make multiple commands work, for e.g below I am trying to run a static html file in chrome and trying to transpile my Sass file:
OUTPUT: Am I doing something wrong ? {Both tasks works fine if ran individually.} Thanks much in advance for your time. |
@foo-baar Do you have to change |
@foo-baar Old version of VSC? What's it say for the version under Help > About? Current version should be 1.10.2. |
Commands per task work even in the old runner, but require 1.9 |
@dbaeumer Your response raised good point to my suspicion: why my vscode was not auto updated or shown me a latest version is available ? Shall it be raised as a separate bug ? (case it's not known issue) (BTW: Updating to latest version fixed the task.json issue, thanks on that). |
@foo-baar yes, please open a separate issue for that. VS Code should inform you about updates. |
Done @dbaeumer, Danke |
Having different commands for different tasks is available since 1.9. I am closing the issue. If anyone sees problems with the support available since 1.9 please open a separate issue. |
It does with the new terminal runner you need to opt in using |
@dbaeumer Hey, this is great. Can you advertize this to the world! See my Stack Overflow question: |
@DrYSG we will. We are currently working on making the terminal runner the default and writing corresponding documentation. |
@dbaeumer here is a idea (suggestion?) If I have 4 background tasks running, I don't really want to keep swapping the display for each task. I would like to be able to merge a few terminal outputs, and have a header (TASK 1: -> output string , etc. ) so that I can follow a few tasks at at a time and see what they are doing. |
@DrYSG you may want to check out my https://github.com/vilic/biu. (Sadly not well-documented) |
Hi,
I cannot find a way to define multiple tasks which executes different commands in the
.vscode/tasks.json
file of my project directory.From what I understood, I can only declare a single TaskConfiguration within this file. Am I wrong?
To make my problem more understandable, let's say I would like to define 3 tasks with their own set of arguments:
foo --arg
bar --arg 1
bar --arg 2
How can I make
tasks.json
reflect this need?The text was updated successfully, but these errors were encountered: