Skip to content

Instantly share code, notes, and snippets.

@rgwood
Last active March 4, 2024 07:05
Show Gist options
  • Select an option

  • Save rgwood/4c498bc5840afc7ce1d36ba97d8165bc to your computer and use it in GitHub Desktop.

Select an option

Save rgwood/4c498bc5840afc7ce1d36ba97d8165bc to your computer and use it in GitHub Desktop.
VS Code Developer Command Prompt

How to add a Developer Command Prompt to VS Code

Using Windows developer CLI tools outside of Visual Studio is way more of a pain than it needs to be. Here's how to set up the VS Developer Command Prompt in VS Code's integrated terminal.

Prerequisites

  • Visual Studio with any workloads you need
  • VS Code

Instructions

Open up the VS Code settings.json file.

First, create an environment variable with the path of the VS batch script that sets variables. The exact path may vary based on your VS version and desired build architecture.

"terminal.integrated.env.windows": { 
    "VsDevVars" : "\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat\""
},

Then create 2 profiles in terminal.integrated.profiles.windows:

"terminal.integrated.profiles.windows": {
    "Dev CMD": {
        "path": "cmd.exe",
        "args": ["/k %VsDevVars%"]
    },
    "Dev PowerShell": {
        "path": "cmd.exe",
        "args": ["/k %VsDevVars% && pwsh"]
    },

Notes

These profiles just run the batch script to set all the necessary environment variables in CMD. The "Dev PowerShell" one then launches PowerShell with all the environment variables inherited.

The environment variable is necessary as a workaround for this VS Code bug. Otherwise we could just stick the batch file path directly in the terminal profiles.

Windows Terminal Bonus

Setting up Developer Command Prompt in Windows Terminal is pretty similar:

{
    "commandline": "cmd.exe /k \"%PROGRAMFILES(X86)%\\Microsoft Visual Studio\\2019\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat\"",
    "guid": "{1748ecca-abdd-4aa4-bcc4-9fca0d045be5}",
    "hidden": false,
    "icon": "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png",
    "name": "Dev CMD",
    "startingDirectory": "%USERPROFILE%"
},
@rgwood

rgwood commented Mar 3, 2024

Copy link
Copy Markdown
Author

I haven’t tried this since 2021; it might be out of date sorry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment