C/C++ VS Code 扩展引发生成错误:“”C/C++“任务的任务提供程序意外提供了”shell“类型的任务。

C/C++ VS Code extension throwing build error: "The task provider for "C/C++" tasks unexpectedly provided a task of type "shell"."

提问人:DeepQuantum 提问时间:5/9/2020 最后编辑:Shlok NangiaDeepQuantum 更新时间:8/11/2023 访问量:9813

问:

当我尝试在 VS Code 中构建 C 任务时,它显示以下消息:

输出仅显示以下内容:The task provider for "C/C++" tasks unexpectedly provided a task of type "shell".

我仍然可以使用 在 cmd 中手动构建我的 C 文件。代替使用快捷键 CTRL+SHIFT+B 似乎也有效。gcc 'filename.c' -o 'output.exe'Terminal -> Run Task

我在 MinGW 中使用 0.28.0-insiders2 C/C++ VS Code 扩展。VS Code 今天刚刚更新到 v. 1.45,我相信这可能是导致此错误的原因,因为我以前没有得到过。

tasks.json文件:

{  
    "version": "2.0.0", 
    "tasks": [
        {
            "label": "Makefile Debug_gcc",
            "type": "shell",
            "command": ["mingw32-make"],
            "args": [
                "--directory=${fileDirname}/", 
                "DEBUG=1", 
                "EXECUTABLE=${fileBasenameNoExtension}Debug"
            ]
        },
        {
            "label": "Makefile Release_gcc",
            "type": "shell",
            "command": ["mingw32-make"],
            "args": [
                "--directory=${fileDirname}/", 
                "DEBUG=0", 
                "EXECUTABLE=${fileBasenameNoExtension}Release"
            ]
        },
        {
            "label": "Release",
            "type": "shell",
            "command": "gcc",
            "args": [
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}Release"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": [
                "$gcc"
            ]
        },
        {
            "label": "Debug",
            "type": "shell",
            "command": "gcc",
            "args": [
                "${file}",
                "-g3",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}Debug"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": [
                "$gcc"
            ]
        },
        {
            "label": "Makefile Debug",
            "type": "shell",
            "command": ["del /S *.o"],
            "dependsOn": [
                "Makefile Debug_gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": [
                "$gcc"
            ]
        },
        {
            "label": "Makefile Release",
            "type": "shell",
            "command": ["del /S *.o"],
            "dependsOn": [
                "Makefile Release_gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": [
                "$gcc"
            ]
        },
        {
            "label": "Makefile Debug + Execute",
            "type": "shell",
            "command": "${fileDirname}/${fileBasenameNoExtension}Debug",
            "dependsOn": [
                "Makefile Debug"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": [
                "$gcc"
            ]
        },
        {
            "label": "Makefile Release + Execute",
            "type": "shell",
            "command": "${fileDirname}/${fileBasenameNoExtension}Release",
            "dependsOn": [
                "Makefile Release"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": [
                "$gcc"
            ]
        },
        {
            "label": "Debug Execute",
            "type": "shell",
            "command": "${fileDirname}/${fileBasenameNoExtension}Debug",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": [
                "$gcc"
            ]
        },
        {
            "label": "Release Execute",
            "type": "shell",
            "command": "${fileDirname}/${fileBasenameNoExtension}Release",
            "group": {
                "kind": "build", 
                "isDefault": true
            },
            "problemMatcher": [
                "$gcc"
            ]
        }
    ]
}
c gcc visual-studio代码

评论

2赞 Allan Chain 5/9/2020
根据此问题评论,它将很快修复。
0赞 questionto42 5/13/2020
您需要更改“C-Cpp:更新频道”设置,在上面的 @Allan Chain 链接中查找 muhammad-osaid-tekfocal 的评论,或者直接在此处获取评论 github.com/microsoft/vscode-cpptools/issues/...您也可以在之后更改设置,请参阅Thomas(为我工作)的评论:github.com/microsoft/vscode-cpptools/issues/...

答:

0赞 Programmerabc 7/16/2021 #1

导航到 .vscode -> 并在其中添加以下两个文件。这是我的文件与代码文件,用于编译、调试和运行 c 代码

任务.json

{
    "tasks": [
      {
        "type": "shell",
        "label": "gcc.exe build active file",
        "command": "F:\\MinGW\\bin\\gcc.exe",//Mention directory to gcc compiler
        "args": [
          "-g",
          "${file}",
          "-o",
          "${fileDirname}\\${fileBasenameNoExtension}.exe"
        ],
        "options": {
          "cwd": "F:\\MinGW\\bin"//Mention dir to bin foler of Mingw
        }
      },
      {
        "type": "shell",
        "label": "gcc build & run active file",
        "command": "F:\\MinGW\\bin\\gcc.exe",//Dir to gcc compiler
        "args": [
          "${file}",
          "-o",
          "${fileDirname}\\${fileBasenameNoExtension}.exe",
          "&&",
          "${fileDirname}\\${fileBasenameNoExtension}.exe"
        ],
        "options": {
          "cwd": "F:\\MinGW\\bin"//Dir to Mingw's bin folder
        },
        "group": {
            "kind": "build",
            "isDefault": true
        }
      }
    ]
}

launch.json文件

{
    "version": "0.2.0",
    "configurations": [
      {
        "name": "gcc.exe build and debug active file",
        "type": "cppdbg",
        "request": "launch",
        "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": false, //set to true to see output in cmd instead
        "MIMode": "gdb",
        "miDebuggerPath": "F:\\MinGW\\bin\\gdb.exe",//Mention the path to gdb inside bin folder of Mingw
        "setupCommands": [
          {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
          }
        ],
        "preLaunchTask": "gcc.exe build active file"
      },
      {
        "name": "gcc build & run active file",
        "type": "cppdbg",
        "request": "launch",
        "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": false, //set to true to see output in cmd instead
        "MIMode": "gdb",
        "miDebuggerPath": "F:\\MinGW\\bin\\gdb.exe",//Mention the path to gdb inside bin folder of Mingw
        "setupCommands": [
          {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
          }
        ],
        "preLaunchTask": "gcc build & run active file"
      }
    ]
}