jsonvisual-studio-codevscode-debuggervscode-tasks

Run custom commands as run configurations in Visual Studio Code


I'm trying to figure out how to make a custom run configuration in Visual Studio Code, and am not succeeding in finding any documentation describing my use case.

I want to make a Run Configuration that runs arbitrary commands that I can set to run my code. This is neccecary because the language I am using doesn't have extensions providing run configurations.

I did find that this is possible with tasks, but I cannot figure out how to run a task by pressing F5 (like you would with a run configuration).

So, this is what I am looking to do: Define something that will run a command (run.exe ${currently selected VSCode file}) when I press F5.


Solution

  • Define this task and put it in .vscode/tasks.json:

    {
      "label": "Run current",
      "type": "shell",
      "command": "run.exe ${file}"
    }
    

    Then add an F5 keybinding in keybindings.json

    { "key": "F5", "command": "-workbench.action.debug.start" },
    { "key": "F5", "command": "-workbench.action.debug.continue" },
    {
      "key": "F5",
      "command": "workbench.action.tasks.runTask",
      "args": "Run current"
    }