# Tasks.json

By [Bother](https://paragraph.com/@bother) · 2023-07-31

---

### [Understanding tasks.json](https://code.visualstudio.com/docs/cpp/config-mingw#_understanding-tasksjson)

The first time you run your program, the C++ extension creates a `tasks.json` file, which you'll find in your project's `.vscode` folder. `tasks.json` stores your build configurations.

Your new `tasks.json` file should look similar to the JSON below:

    {
      "tasks": [
        {
          "type": "cppbuild",
          "label": "C/C++: g++.exe build active file",
          "command": "C:\\msys64\\mingw64\\bin\\g++.exe",
          "args": [
            "-fdiagnostics-color=always",
            "-g",
            "${file}",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe"
          ],
          "options": {
            "cwd": "${fileDirname}"
          },
          "problemMatcher": ["$gcc"],
          "group": {
            "kind": "build",
            "isDefault": true
          },
          "detail": "Task generated by Debugger."
        }
      ],
      "version": "2.0.0"
    }
    

**Note**: You can learn more about `tasks.json` variables in the [variables reference](https://code.visualstudio.com/docs/editor/variables-reference).

The `command` setting specifies the program to run; in this case that is g++.

The `args` array specifies the command-line arguments that will be passed to g++.

These arguments are listed in this file **_in the specific order_** expected by the compiler.

[Subscribe](null)

This task tells g++ to take the active file (`${file}`), compile it, and create an executable file in the current directory (`${fileDirname}`) with the same name as the active file but with the `.exe` extension (`${fileBasenameNoExtension}.exe`).

For us, this results in `helloworld.exe`.

The `label` value is what you will see in the tasks list; you can name this whatever you like.

The `detail` value is what you will as the description of the task in the tasks list.

It's highly recommended to rename this value to differentiate it from similar tasks.

From now on, the play button will read from `tasks.json` to figure out how to build and run your program.

You can define multiple build tasks in `tasks.json`, and whichever task is marked as the default will be used by the play button.

In case you need to change the default compiler, you can run **Tasks: Configure Default Build Task** in the Command Palette.

Alternatively you can modify the `tasks.json` file and remove the default by replacing this segment:

        "group": {
            "kind": "build",
            "isDefault": true
        },
    

with this:

    "group": "build",
    

### [Modifying tasks.json](https://code.visualstudio.com/docs/cpp/config-mingw#_modifying-tasksjson)

You can modify your `tasks.json` to build multiple C++ files by using an argument like `"${workspaceFolder}/*.cpp"` instead of `${file}`.

This will build all `.cpp` files in your current folder.

You can also modify the output filename by replacing `"${fileDirname}\\${fileBasenameNoExtension}.exe"` with a hard-coded filename (for example `"${workspaceFolder}\\myProgram.exe"`).

**_${workspaceFolder}/\*.cpp_**

    "${fileDirname}\\${fileBasenameNoExtension}.exe"
    

Line 14, can be rename to “${workspaceFolder}\\\\myProgram.exe”

![](https://storage.googleapis.com/papyrus_images/f926f06ab8e95fddfdcdf96290404a1e94889e6115c5d4501d1031772503e7bb.png)

![Compiled to new program name](https://storage.googleapis.com/papyrus_images/8ef9471a66bb6c521197b6b89b0259f4053909f2d7958dd22bb1fc3d17cf255b.png)

Compiled to new program name

---

*Originally published on [Bother](https://paragraph.com/@bother/tasks-json)*
