gpt4 book ai didi

visual-studio-code - 几个 "build tasks"for visual studio code (python)

转载 作者:行者123 更新时间:2023-12-02 01:09:35 25 4
gpt4 key购买 nike

我的 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 命令),那么它将被添加到构建任务中。我将如何添加这个?

最佳答案

您可以在 tasks.json 中定义多个任务,方法是将一组任务对象分配给 tasks 属性,如下所示:

{
// 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" 键绑定(bind)。

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

完成后,您可以在使用workbench.action.tasks.runTask 命令时选择任务,如下所示:

Choose which task to run

您还可以通过设置任务的 "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

关于visual-studio-code - 几个 "build tasks"for visual studio code (python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45654050/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com