Home > OS >  "No matching commands" for custom VS Code task
"No matching commands" for custom VS Code task

Time:11-07

I'm trying to figure out how to create and use custom tasks.

I have been able to create a tasks.json file, but when I try to run the task from the command palette, nothing shows up.

My current .vscode/tasks.json file contains:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "echo",
            "type": "shell",
            "command": "echo Hello"
        }
   ]
}

I have also tried:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "New Test Task",
            "type": "shell",
            "command": "echo 'hello new task'",
            "windows": {
                "command": "echo 'hello new task'"
            },
            "presentation": {
                "reveal": "always",
                "panel": "new"
            }
        }
    ]
}

And I have also tried the following combinations of folder/file:

  • .vs/tasks.json
  • .vs/tasks.vs.json
  • .vscode/tasks.vs.json
  • .vscode/tasks.json

Despite all of this, I keep getting a "No matching commands" error message. Is there something that I have overlooked or am doing wrong? Any guidance will be much appreciated.

Screenshot:
No matching commands

CodePudding user response:

From the command palette, it requires 2 (or 3) steps/commands.

First, you need to get "Tasks: Run Tasks" in the command palette.
(By just entering "tasks", you should see it)

command palette > run tasks

Then, after selecting that, it should list you all the tasks defined in your .vscode/tasks.json (yes, this is the correct folder/file combination as seen from the example in the command palette > list of tasks

Now, depending on the task, it may prompt a third selection, like this one for your echo task:

command palette > task options

If you want a single-step/command, you can use the other options of the Tasks: command group such as re-running the last run task or configuring a default task:

command palette > tasks options

Or instead of the command palette, use a keybinding/shortcut to run your task: enter image description here

Then configure the shortcut key command as follows

{
  "key": "f8",
  "command": "workbench.action.tasks.runTask",
  // "args": "echo", // You can also define your task label directly
  "args": "${input}",
}

enter image description here

Finally, enter the shortcut key Use the shortcut key F8 to see the results of the task output enter image description here

  • Related