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

Viewed 3189

When I try to build a C task in VS Code it shows the following message:

The Output just shows this: The task provider for "C/C++" tasks unexpectedly provided a task of type "shell".

I can still manually build my C files in cmd using gcc 'filename.c' -o 'output.exe'. Going to Terminal -> Run Task instead of using the shortcut CTRL+SHIFT+B also seems to work.

I use the 0.28.0-insiders2 C/C++ VS Code extension with MinGW. VS Code just updated today to v. 1.45 and I believe that might be the cause for this error as I haven't gotten it before.

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"
            ]
        }
    ]
}
1 Answers

Naviagte to .vscode -> and add the following two files there. This are my file vs code file for compiling, debugging and running c code.

task.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"
      }
    ]
}
Related