这是一个网页,他们在其中解释了有关 task.json 文件的更多信息。
https://code.visualstudio.com/docs/editor/tasks
构建任务是项目特定的。要创建一个新项目,请在 VSCode 中打开一个目录。
按照说明here,按Ctrl+Shift+P,输入Configure Tasks,选择它并按Enter。
tasks.json 文件将被打开。将以下构建脚本粘贴到文件中,并保存:
{
"version": "0.1.0",
"command": "make",
"isShellCommand": true,
"tasks": [
{
"taskName": "Makefile",
// Make this the default build command.
"isBuildCommand": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "always",
// No args
"args": ["all"],
// Use the standard less compilation problem matcher.
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
现在转到File->Preferences->Keyboard Shortcuts 并为构建任务添加以下键绑定:
// Place your key bindings in this file to overwrite the defaults
[
{ "key": "f8", "command": "workbench.action.tasks.build" }
]
现在,当您按下F8 时,Makefile 将被执行,错误将在编辑器中加下划线。