JoshCode
JoshCode

Reputation: 107

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.

Upvotes: 7

Views: 7371

Answers (2)

AlexM
AlexM

Reputation: 1183

I handled this by putting my commands in a Python file build.py, and then defining .vscode/launch.json to be:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Build",
            "type": "debugpy",
            "request": "launch",
            "program": "build.py",
            "console": "integratedTerminal"
        }
    ]
}

That way whenever I press F5 it starts a Python debugger that executes build.py, no matter what current file I have open in VS Code.

Upvotes: 1

rioV8
rioV8

Reputation: 28848

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"
}

Upvotes: 9

Related Questions