visual-studio-codecl

How to integrate Developer Command Prompt for VS 2022 as Terminal in VS Code


I would like to have the Microsoft VS C++ compiler cl available in VisualStudio Code.

I have Visual Studio Build Tools installed and can call cl from the Developer Command prompt.

The default way recommended by Microsoft to get VS Code to use the cl compiler is to call VS Code from the Developer Command prompt.

I would like to do it differently, with a terminal that I can call from VS Code and make it the default terminal if needed.

In Windows Terminal, I get the automatically generated Developer Command prompt entry with the command line:

cmd.exe /k "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\VsDevCmd.bat" -arch=x64 -host_arch=x64`

or

powershell.exe -NoExit -Command "&{Import-Module """C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"""; Enter-VsDevShell 0d0637f3 -SkipAutomaticLocation -DevCmdArguments """-arch=x64 -host_arch=x64"""}"

If I paste this line into an existing vscode terminal, it works and I can use the cl compiler. But I can't manage to get it into an integrated terminal in settings.json.

This is what I tried in the settings.json:

"Developer Command Prompt for VS 2022": {
    "path": [
        "${env:windir}\\Sysnative\\cmd.exe /k \"C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\Common7\\Tools\\VsDevCmd.bat\" -arch=x64 -host_arch=x64",
        "${env:windir}\\System32\\cmd.exe /k \"C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\Common7\\Tools\\VsDevCmd.bat\" -arch=x64 -host_arch=x64"
    ],
    "overrideName": true,
    "args": [],
    "icon": "terminal-cmd"
},

Since VScode is pretty smart, it recognizes that this won't work and doesn't even list it as an entry within the available terminals.

Furthermore, i have absolutely no idea what to do with the commandline given for PowerShell, notably the three doublequotes after Import-Module and how to handle them.


Solution

  • Try the following to load VsDevCmd.bat in cmd.exe from the VSCode integrated terminal.

    For running it through PowerShell, you should be able to just replace the path with PowerShell, and alter the arguments to match accordingly (/k would become -NoExit, etc).

    "VsDevCmd (2022)": {
        "path": [
            "${env:windir}\\Sysnative\\cmd.exe",
            "${env:windir}\\System32\\cmd.exe"
        ],
        "args": [
            "/k",
            // Path below assumes a VS2022 Community install; 
            // update as appropriate if your IDE installation path
            // is different, or if using the standalone build tools
            "C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/Tools/VsDevCmd.bat",
            "-arch=x64",
            "-host_arch=x64"
        ],
        "overrideName": true,
        "icon": "terminal-cmd"
    },
    

    enter image description here