VScode调试模式显示“找不到指定的任务”

9

在尝试在vscode中启动Debug会话时,它会抛出一个关于未找到指定任务的错误。我已经尝试了其他SO问题的解决方案,比如这个,但是没有成功。

launch.json:

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
    {
      ...
    },
    {
        "name": "MSEventHubs_Audit",
        "type": "python",
        "request": "launch",
        "program": "${workspaceFolder}/audit-events.py",
        "console": "integratedTerminal",
        "args": [
            "config/config.ini",
        ],
        "envFile": "${workspaceFolder}/.env",
        "env": {"PYTHONPATH": "${workspaceRoot}"},
        "justMyCode": false,
        "preLaunchTask": {
            "task": "audit_tunnel"
        }
    },
    {
     ...
    },
]
}

tasks.json:

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"command": "",
"args": [],
"tasks": [
    {
        "label": "activate_key",
        "type": "shell",
        "command": "smartOS_card_pin.sh",
        "args": [
            "${inputs:cardos_pass}"
        ],
        "group": "build",
    },
    {
        "label": "audit_tunnel",
        "type": "shell",
        "group": "build",
        "command": "ssh",
        "args": [
            "-NL",
            "port1:127.0.0.1:port2",
            "my_host"
        ],
        "dependsOn": "activate_key"
    },
    {
      ...
    }
],
"inputs": [
    {
    "id": "cardos_pass",
    "type": "promptString",
    "password": true
    }
]
}

我一直在看,但是无法弄清楚自己做错了什么。证明我的任务被VSCode识别的方式是当弹出消息出现时。

在此输入图片描述

我点击“配置任务”,“audit_tunnel”出现作为编辑选项。

在此输入图片描述

我错过了什么吗?


我会从你的tasks.json文件中删除"command": "", "args": [],,因为这看起来是之前的语法。请参考https://code.visualstudio.com/Docs/editor/tasks#_migrating-to-tasks-200。另外,如果你只运行`audit_tunnel`,它能被找到吗?你可以在里面加一个echo以便于测试。 - Mark
是的 @Mark,我可以直接运行任务。你的建议没有起作用。 - samthegolden
1个回答

20

更改:

"preLaunchTask": {
            "task": "audit_tunnel"
        }

收件人:

"preLaunchTask": "audit_tunnel"

1
以上至少对我有所改善,现在更具体地显示为“无法找到任务'/home/user/some/task.json'”,尽管该文件存在。 - JoeManiaci

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接