5

The Visual Studio Code documentation provides example tasks.json configuration that allows either typescript compilation, or markdown compilation. It does not clarify how to achieve both simultaneously.

How can that be done?

Here is a summary of the two examples...

Typescript Example

If I want VSCode to perform a typescript build step, the directions say I need to install typescript (npm install -g typescript) and then define the following task:

{
    "version": "0.1.0",
    "command": "tsc",
    "isShellCommand": true,
    "showOutput": "silent",
    "args": ["*.ts"],
    "problemMatcher": "$tsc"
}

Markdown Example

If I want VSCode to perform a Markdown build step, the documentation says I could install a markdown plugin of my choice (e.g. npm install -g marked), and then define a task:

{
    "version": "0.1.0",
    "command": "marked",
    "isShellCommand": true,
    "args": ["sample.md", "-o", "sample.html"]
}

Now What?

Evidently, the tasks.json may contain exactly one JSON object. Thus I cannot simply join both definitions above with a comma. On the other hand, it is possible to have multiple tasks defined within the overall task definition:

{
    "version": "0.1.0",
    "command": "<what goes here?>",
    "isShellCommand": true,
    "suppressTaskName": true, //or false?

    "tasks": [
        {
            "taskName": "Launch Typescript"
        },
        {
            "taskName": "Launch Markdown"
        }        
    ]
}

The above is a skeleton of legal syntax, but it is unclear how to complete the story. I am aware of discussion here and there about how to solve these kinds of issues, but there seems to be a fundamental disconnect. For example, how does VSCode know that it is supposed to execute both tasks when I press ctrl+shift+b?

Assuredly the developers of VSCode have a more direct and simpler way to accommodate multiple build tasks. Does anyone know what that is?

Gama11
  • 31,714
  • 9
  • 78
  • 100
Brent Arias
  • 29,277
  • 40
  • 133
  • 234

1 Answers1

0

You are almost at the right answer.

You can define multiple build task, as shown in your last example.

What you didn't realize is that you can override global properties within the task. Meaning in one task, you can define "command" and "args" one way and in the other define it with totally different values.

In a sense, copy the meat of two examples you have above into each task in your last example

Tobiah Zarlez
  • 1,680
  • 1
  • 12
  • 13
  • Actually, it is not possible to override the "command" property...and that is the crux of the issue. VSCode gives both intellisense and execution errors when trying that approach. Too bad - because that would be a huge help if it had worked. – Brent Arias Feb 14 '16 at 02:09
  • Oh interesting, I guess I was wrong on that. (On phone, can't test) - But if that is the case, you could always make a simple script and use that as the command instead (It's just calling a program, you could put a full path to any exe on your system if you wanted) and then in that script, take one of the arguments for which program you want to run. – Tobiah Zarlez Feb 14 '16 at 11:10
  • 1
    Yes, creating a "common script that has args passed" is the approach others are using. Still, it would be cool if the authors of VS code documented their own approach so that the rest of us don't have to go through this slow discovery process of (1) the technique and (2) the refinement of the technique. For example, I want my tasks.json to be cross platform. What is the suggested model for that? I'll figure it out, but why should every VS Code developer figure that out from scratch? – Brent Arias Feb 14 '16 at 17:36