【发布时间】:2017-05-07 21:23:10
【问题描述】:
在使用.vscode/launch.json 调试项目时,有没有办法执行ssh 命令?
例如:ssh -i xxxxx。
或者是否可以创建一个可以从 F1 命令面板弹出窗口运行的命令?类似RunCustomCommandxx。
【问题讨论】:
在使用.vscode/launch.json 调试项目时,有没有办法执行ssh 命令?
例如:ssh -i xxxxx。
或者是否可以创建一个可以从 F1 命令面板弹出窗口运行的命令?类似RunCustomCommandxx。
【问题讨论】:
您可以在tasks.json 文件中定义task,并在launch.json 中将其指定为preLaunchTask,该任务将在调试开始之前执行。
例子:
在tasks.json中:
对于 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 版(更新和推荐):
{
"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
【讨论】:
Address already in use 说的还不够吗?用ssh连接机器,试试netstat -lnpt看看进程是不是already using the address。
格式改变了。 Visual Studio Code 可以为您创建tasks.json 文件。在您的 launch.json 文件和任何配置对象中,只需定义 preLaunchTask 以强制自动创建 tasks.json 模板文件:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "launch program",
"skipFiles": [ "<node_internals>/**"],
"preLaunchTask": "myShellCommand",
"program": "${workspaceFolder}/test.js"
}
]
}
如果您没有配置文件tasks.json:
然后将为您创建tasks.json 模板文件。将您的命令添加到command,并将您在preLaunchTask 中输入的名称添加到label:
{
"version": "2.0.0",
"tasks": [
{
"label": "myShellCommand",
"type": "shell",
"command": "echo goodfood"
}
]
}
【讨论】:
对我来说,我只需要一个环境变量,这是不同的。你不想要这个任务,因为(至少对我来说)启动器运行时它不起作用。
感谢here,在我的启动器 (launch.json) 条目中,我让它像这样工作:
"environment": [{
"name": "ENVIRONMENT_VARIABLE_NAME",
"value": "${workspaceFolder}/lib" //Set to whatever value you want.
}],
【讨论】:
我的配置版本允许只运行定义的任务并继续(在我的情况下,任务是运行当前打开的Groovy 文件):
"configurations": [
{
"name": "Launch groovy",
"request": "launch",
"type": "coreclr",
"preLaunchTask": "groovy",
"program": "cmd.exe",
"args": ["/c"],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"internalConsoleOptions": "neverOpen"
}
]
还有任务:
"tasks": [
{
"label": "groovy",
"type": "shell",
"command": "groovy ${file}"
}
]
【讨论】:
"cwd": "${workspaceFolder}" 参数起到了作用。
适用于正在搜索如何运行 Flutter 构建命令的 Flutter 开发人员。 在tasks.json中添加
"tasks": [
{
"type": "flutter",
"command": "flutter",
"args": [
"pub",
"run",
"build_runner",
"build",
"--delete-conflicting-outputs"
],
"problemMatcher": [
"$dart-build_runner"
],
"group": "build",
"label": "flutter: flutter pub run build_runner build --delete-conflicting-outputs"
},
]
然后从 vscode 你可以尝试“运行任务”它会告诉你flutter: flutter pub run build_runner build --delete-conflicting-outputs
这样你就不需要记住和输入终端源代码生成/构建命令
【讨论】: