我的tasks.json看起来像这样:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
// A task runner that runs a python program
"command": "python3",
"presentation": {
"echo": true,
"reveal": "always",
"focus": true
},
"args": [
"${file}"
]
}
当我运行ctrl+shift+B
时,顶部面板会询问"选择要运行的构建任务"以及一个替代方案:python3
。现在,如果我想添加一个新的构建任务(例如带有scrapy的runspider
命令),那么它就会被添加到构建任务中。我该怎么做呢?
答案 0 :(得分:2)
您可以通过为tasks属性分配一组任务对象,在tasks.json
中定义多个任务,如下所示:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"taskName": "python3",
"type": "shell",
"command": "python3",
"args": [
"${file}"
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": true
}
},
{
"taskName": "runspider",
"type": "shell",
"command": "runspider"
}
]
}
此外, Ctrl + Shift + B 运行默认构建任务,因此您可能希望设置"workbench.action.tasks.runTask"
键绑定
{
"key": "ctrl+shift+b",
"command": "workbench.action.tasks.runTask"
}
完成后,您可以在使用workbench.action.tasks.runTask
命令时选择任务,如下所示:
您还可以通过在任务上设置"group"
属性来选择默认构建任务。在此处,在以下代码段中,您的"python3"
任务将作为默认构建任务运行。
...
"tasks": [
{
"taskName": "python3",
"type": "shell",
"command": "python3",
"args": [
"${file}"
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": true
},
"group": {
"kind": "build",
"isDefault": true
}
},
{
"taskName": "runspider",
"type": "shell",
"command": "runspider"
}
]
...
您可以在此处详细了解任务:Tasks in VSCode