microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.54k stars 1.56k forks source link

The "inputs" section is not working in `tasks.json`. #12845

Open MellowOrchid opened 1 month ago

MellowOrchid commented 1 month ago

Environment

Bug Summary and Steps to Reproduce

Bug Summary:

  1. Prepare a clean environment for C or C++ source file, which excludes tasks.json and launch.json under .vscode folder.
  2. Write hello_world.cpp.
  3. Generate a tasks.json by click Run C/C++ File. It should be able to run correctly.
  4. Add inputs section that includes "id": "ext" to tasks.json and append ${input:ext} to the last line in args.
  5. Run the .cpp file again, and VS Code will tell you "Variable 'ext' must be defined in an 'inputs' section of the debug or task configuration."

Debugger Configurations

tasks.json:

{
    "inputs": [
        {
            "id": "ext",
            "type": "pickString",
            "description": "Choose the extension",
            "options": [
                ".app",
                ".exe"
            ],
            "default": ".app"
        }
    ],
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++ build active file",
            "command": "g++",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${cwd}/bin/${fileBasenameNoExtension}${input:ext}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Generated task by Debugger."
        }
    ],
    "version": "2.0.0"
}

launch.json: None

Debugger Logs

VS Code window: Variable 'ext' must be defined in an 'inputs' section of the debug or task configuration.

Other Extensions

None, only C/C++ by Microsoft installed

Additional Information

Actually, I want the tasks.json could use different extension name by judging the platform.

I want to compile C/C++ source code on Linux and Windows by using one 'tasks.json' and no need to install other extension.

MellowOrchid commented 2 weeks ago

Not resolved in VS Code v1.95.1 and C/C++ v1.22.11.