在 Visual Studio Code 中构建当前打开的文件 [英] Build currently opened file in Visual Studio Code

查看:30
本文介绍了在 Visual Studio Code 中构建当前打开的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作区,用于编写较小的测试程序来练习概念.因此,在 VS Code 中,我对文件夹中的每个文件都有一个构建任务.

I have a workspace that I use for smaller test programs I write to practice concepts. Hence, in VS Code, I have a build task for each file in the folder.

默认情况下,VS Code 使用 "isDefault": true, 标志构建任务.理想情况下,我想找到一种方法来构建当前打开的文件,这样当我切换正在编辑的文件时,我不需要手动将标志重置为我想要使用的构建任务.

By default, VS Code builds the task with the "isDefault": true, flag. Ideally, I would like to figure out a way for me to build the currently opened file, so that when I switch files I am editing, I do not need to manually reset the flag to the build task I want to use.

据我所知,VS Code 任务文档 没有提供解决方案.必须有一种方法可以在不手动调整标志的情况下完成此操作.任何帮助表示赞赏.

To my knowledge, the VS Code Tasks Documentation doen't provide a solution. There must be a way to accomplish this without manually adjusting the flag. Any help is appreciated.

推荐答案

在 Rob's Answer 上构建,您还可以通过添加到 keybindings.json 来设置快捷键组合来触发每个任务,例如

To Build on Rob's Answer, you can also set a shortcut key combination to trigger each task by adding to keybindings.json, e.g.

{
    "key": "ctrl+h",
    "command": "workbench.action.tasks.runTask",
    "args": "Run tests"
}

其中 args 组件被替换为任务名称.

where the args component is replaced with the task name.

您可以将其与 tasks.json 中的 ${file} 结合使用,以区分不同的构建类型.

You could use this in combination with ${file} in tasks.json to differentiate between the separate build types.

例如按 Ctrl+h 为 python 和 Ctrl+Shift+h 为 tsc

e.g. hit Ctrl+h for python and Ctrl+Shift+h for tsc

这篇关于在 Visual Studio Code 中构建当前打开的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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