How to run a command in Visual Studio Code with launch.json
visual-studio-code
Solution
You can define a task in your `tasks.json` file and specify that as the `preLaunchTask` in your `launch.json` and the task will be executed before debugging begins.
Example:
In tasks.json:
For version 0.1.0:
{
"version": "0.1.0",
"tasks": [{
"taskName": "echotest",
"command": "echo", // Could be any other shell command
"args": ["test"],
"isShellCommand": true
}]
}
For version 2.0.0 (newer and recommended):
{
"version": "2.0.0",
"tasks": [{
"label": "echotest",
"command": "echo", // Could be any other shell command
"args": ["test"],
"type": "shell"
}]
}
In launch.json:
{
"configurations": [
{
// ...
"preLaunchTask": "echotest", // The name of the task defined above
// ...
}
]
}
Tasks documentation: https://code.visualstudio.com/docs/editor/tasks
Launch configuration: https://code.visualstudio.com/docs/editor/debugging#_launch-configurations
Problem
Is there a way to execute an `ssh` command when debugging a project with `.vscode/launch.json`? For example: `ssh -i xxxxx`. Or is it possible to create a command that you can run from the F1 command palette pop-up? Something like `RunCustomCommandxx`.