有没有办法在 VS Code 中设置调用构建任务的快捷方式? [英] Is there a way to set up a shortcut to call Build Tasks in VS Code?

查看:23
本文介绍了有没有办法在 VS Code 中设置调用构建任务的快捷方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我在 Visual Studio Code(不是 Visual Studio)中设置了一个构建任务.当我按 Ctrl+Shift+B 时,我会得到我的构建任务列表,然后我必须选择我的任务,然后它会编译并运行我的程序.

Currently, I have a Build Task set up in Visual Studio Code (not Visual Studio). When I press Ctrl+Shift+B, I get a list of my build tasks, I then have to select my task and then it will compile and run my program.

有没有更简单的方法来做到这一点,而不是 Ctrl+Shift+B -> Enter,我只需按一个按钮就可以运行预设的构建任务?键盘按钮或 GUI 按钮都可以很好地工作.

Is there an easier way to do this, so instead of Ctrl+Shift+B -> Enter, I can just press one button and have a preset Build Task run? Either a keyboard button or a GUI button will work great.

推荐答案

通过 Terminal -> Configure Default Build Task... 将任务标记为默认构建任务... 这只是将以下内容添加到tasks.json 中的任务:

Mark the task as your default build task via Terminal -> Configure Default Build Task... This simply adds the following to the task in tasks.json:

"group": {
    "kind": "build",
    "isDefault": true
}

之后,Ctrl+Shift+B将直接运行任务.

After that, Ctrl+Shift+B will run the task directly.

此外,您还可以有一个带有 "kind": "test" 的默认 test 任务.该任务可以使用 Tasks: Run Test Task 命令直接运行(默认情况下没有分配快捷方式).

Additionally, you could also have a default test task with "kind": "test". That task can be directly run with the Tasks: Run Test Task command (no shortcut assigned by default).

最后,如果有两个快捷键还不够(或者你不想修改tasks.json),你可以设置键绑定到直接按任务名称运行任务:

And finally, if having two shortcuts is still not enough (or you don't want to modify tasks.json), you can set up keybindings to run tasks directly by their name:

{
    "key": "ctrl+b",
    "command": "workbench.action.tasks.runTask",
    "args": "run"
}

用您的构建任务的标签替换 run.

Replacing run with the label of your Build Task.

要打开 keybindings.jsonCtrl+K Ctrl+S或点击文件 -> 首选项 -> 键盘快捷键.如果文件以前是空的,您可能需要添加 [].

To open keybindings.json press Ctrl+K Ctrl+S or click File -> Preferences -> Keyboard Shortcuts. You may need to add [] if the file was previously empty.

这篇关于有没有办法在 VS Code 中设置调用构建任务的快捷方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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