title: How to get Visual Studio to execute build commands in a msys2 shell?
body: <p>I managed to build and debug my C++ (mingw) project with Visual Studio Code. I want to be able to do it with Visual Studio 2019 (as discussed <a href="https://devblogs.microsoft.com/cppblog/using-mingw-and-cygwin-with-visual-cpp-and-open-folder/" rel="nofollow noreferrer">here</a>). To do this, it seems I need to run the build commands in a different shell. This is the config I'm using for VS Code:</p>
  
  <p>in <code>.vscode/settings.json</code>:</p>
  
  <pre><code>{
      "terminal.integrated.shell.windows": "C:\\tools\\msys64\\usr\\bin\\bash.exe",
      "terminal.integrated.shellArgs.windows": [
          "--login",
          "-i"
      ],
      "terminal.integrated.env.windows": {
          "MSYSTEM": "MINGW64",
          "CHERE_INVOKING":"1"
      }
  }
  </code></pre>
  
  <p>in <code>.vscode/tasks.json</code>:</p>
  
  <pre><code>{
      "version": "2.0.0",
      "tasks": [
          {
              "type": "shell",
              "label": "build",
              "command": "sh",
              "args": [
                  "build.sh"
              ],
              "options": {
                  "cwd": "${workspaceFolder}"
              },
              "problemMatcher": [
                  "$gcc"
              ],
              "group": {
                  "kind": "build",
                  "isDefault": true
              }
          }
      ]
  }
  </code></pre>
  
  <p>This works really well. My <code>build.sh</code> script executes various commands to compile my project.</p>
  
  <p>But I want to be able to develop my project in Visual Studio 2019 (not Visual Studio Code), since VS Code is still lacking in a couple of "must-have" C++ development features.</p>
  
  <p>But my problem is that I don't understand how I can make Visual Studio execute the build commands <strong>in a different shell like VS Code does</strong>. So the build commands don't work, since they are not executed in the msys2, mingw64 environment.</p>
  
  <p>This i my <code>.vs/tasks.vs.json</code> file:</p>
  
  <pre><code>{
    "version": "0.2.1",
    "tasks": [
      {
        "taskLabel": "build",
        "appliesTo": "/",
        "type": "launch",
        "command": "sh",
        "args": ["build.sh"],
        "env": "Mingw64",
        "customLaunchCommand": "C:\\tools\\msys64\\usr\\bin\\bash.exe",
        "customLaunchCommandArgs": [
          "--login",
          "-i"
        ]
      }
    ]
  }
  </code></pre>
  
  <p>This config file was my best bet on how to make the <code>sh build.sh</code> command be executed in the shell opened with the command <code>C:\tools\msys64\usr\bin\bash.exe --login -i</code>.</p>
  
  <p>Can someone tell me how to make Visual Studio 2019 execute the build commands in a msys2 shell, like VS Code does?</p>
  
  <p><strong>EDIT</strong>:</p>
  
  <p>So maybe I'm getting closer with this, and maybe not. Following the examples in the Visual Studio 2019 docs, my <code>.vs/CppProperties.json</code> now looks like this:</p>
  
  <pre><code>{
    "configurations": [
      {
        "inheritEnvironments": [
          "mingw_64"
        ],
        "name": "Mingw64",
        "includePath": [
          "${workspaceRoot}\\**"
        ],
        "intelliSenseMode": "linux-gcc-x64",
        "environments": [
          {
            "MINGW_PREFIX": "C:\\tools\\msys64",
            "MINGW_CHOST ": "x86_64-w64-mingw32",
            "MINGW_PACKAGE_PREFIX": "mingw-w64-x86_64",
            "MSYSTEM": "MINGW64",
            "MSYSTEM_CARCH": "x64_64",
            "MSYSTEM_PREFIX": "${env.MINGW_PREFIX}",
            "SHELL": "${env.MINGW_PREFIX}\\usr\\bin\\bash.exe --login -i",
            "TEMP": "${env.MINGW_PREFIX}/../tmp",
            "TMP": "${env.TEMP}"
          }
        ]
      }
    ]
  }
  </code></pre>
  
  <p>And my <code>.vs/tasks.vs.json</code>:</p>
  
  <pre><code>{
    "version": "0.2.1",
    "tasks": [
      {
        "taskLabel": "build",
        "appliesTo": "build.sh",
        "contextType": "build",
        "type": "default",
        "command": "sh",
        "args": [
          "build.sh"
        ],
        "inheritEnvironments": [ "Mingw64" ]
      }
    ]
  }
  </code></pre>
  
  <p>But still, it appears Visual Studio still does not use the msys2 shell to execute the build task. How to actually use a "configuration" defined in the <code>CppProperties.json</code> file is a mystery to me...</p>