如何修复 VSCode 中的 "Could not find the task C/C++: gcc build active file." 错误?

How do I fix "Could not find the task C/C++: gcc build active file." error in VSCode?

我正在 VSCode 中开发 C 程序,我正在 Windows 运行ning Ubuntu 20.04 via Windows Subsystem for Linux(WSL 1.0)。过去几周一切正常,直到今天我遇到此 post 标题中的错误消息。我将在下面包括 tasks.json 和 launch.json(两者都在 .vscode 文件夹中)。

tasks.json 文件:

{
"version": "2.0.0",
"tasks": [
    {
        "type": "cppbuild",
        "label": "C/C++: gcc build active file",
        "command": "/usr/bin/gcc",
        "args": [
            "-g",
            "${file}",
            "-o",
            "${fileDirname}/${fileBasenameNoExtension}"
        ],
        "options": {
            "cwd": "${workspaceFolder}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "detail": "compiler: /usr/bin/gcc"
    }
]
}

和 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": "gcc - Build and debug active file",
        "type": "cppdbg",
        "request": "launch",
        "program": "${fileDirname}/${fileBasenameNoExtension}",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": true,
        "MIMode": "gdb",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ],
        "preLaunchTask": "C/C++: gcc build active file",
        "miDebuggerPath": "/usr/bin/gdb"
    }
]
}

在终端输出中,我在尝试 运行 基本程序时收到以下消息:

Error: The cppbuild task detection didn't contribute a task for the following configuration:
{
    "type": "cppbuild",
    "label": "C/C++: gcc build active file",
    "command": "/usr/bin/gcc",
    "args": [
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}"
    ],
    "options": {
        "cwd": "${workspaceFolder}"
    },
    "problemMatcher": [
        "$gcc"
    ],
    "group": {
        "kind": "build",
        "isDefault": true
    },
    "detail": "compiler: /usr/bin/gcc"
}
The task will be ignored.

事实证明,降级 C/C++ 扩展是答案。最近的更新导致出现此问题。

而不是:

"类型": "cppbuild",

对我有用:

"类型": "shell",