如何使用 launch.json 在 Visual Studio Code 中运行命令 [英] How to run a command in Visual Studio Code with launch.json

查看:312
本文介绍了如何使用 launch.json 在 Visual Studio Code 中运行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 .vscode/launch.json 调试项目时,有没有办法执行 ssh 命令?

Is there a way to execute an ssh command when debugging a project with .vscode/launch.json?

例如:ssh -i xxxxx.

或者是否可以创建一个可以从 F1 命令面板弹出窗口运行的命令?类似于 RunCustomCommandxx.

Or is it possible to create a command that you can run from the F1 command palette pop-up? Something like RunCustomCommandxx.

推荐答案

您可以定义一个任务 在您的 tasks.json 文件中,并将其指定为 launch.json 中的 preLaunchTask,任务将在调试开始之前执行.

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.

示例:

在tasks.json中:

对于 0.1.0 版:

For version 0.1.0:

{
    "version": "0.1.0",
    "tasks": [{
        "taskName": "echotest",
        "command": "echo", // Could be any other shell command
        "args": ["test"],
        "isShellCommand": true
    }]
}

对于 2.0.0 版(更新和推荐):

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

在launch.json中:

{
    "configurations": [
        {
            // ...
            "preLaunchTask": "echotest", // The name of the task defined above
            // ...
        }
    ]   
}

任务文档:https://code.visualstudio.com/docs/editor/tasks

启动配置:https://code.visualstudio.com/docs/editor/debugging#_launch-configurations

这篇关于如何使用 launch.json 在 Visual Studio Code 中运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆