Skip to content

Instantly share code, notes, and snippets.

@adamelliotfields
Last active January 24, 2026 15:53
Show Gist options
  • Select an option

  • Save adamelliotfields/973e6f3906ac2183c7786164374f9258 to your computer and use it in GitHub Desktop.

Select an option

Save adamelliotfields/973e6f3906ac2183c7786164374f9258 to your computer and use it in GitHub Desktop.
MSVC (cl) in Windows Terminal

I wanted to build C programs on Windows 11 without WSL. I then wanted to be able to open a terminal tab with the MSVC compiler/linker (cl) environment set up.

Note

These instructions target x64; substitute the appropriate values for ARM.

Installation

Install Visual Studio Build Tools via Winget:

winget install --source winget --id Microsoft.VisualStudio.2022.BuildTools

Run the Visual Studio Installer application and add the following components:

  • MSVC v143 - VS 2022 C++ x64/x86 build tools (Latest)
  • Windows 11 SDK (Latest)

The SDK provides the headers and libraries the linker expects.

Command Prompt

Load the developer environment:

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

Windows Terminal profile

{
  "guid": "{8c476194-fb68-4445-8054-6412c6586df3}",
  "name": "Developer Command Prompt",
  "commandline": "%ComSpec% /k \"\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\Common7\\Tools\\VsDevCmd.bat\" -arch=x64 -host_arch=x64\""
}

Notes

  • %ComSpec% is the environment variable for cmd.exe.
  • /k runs the command and keeps the shell open (interactive).
  • /c would have run the command and exited (non-interactive).

PowerShell

Import the DevShell module:

Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"

Enter Developer PowerShell:

Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools" -DevCmdArguments "-arch=x64 -host_arch=x64"

Windows Terminal profile

Wrap the commands in a script block:

{
  "guid": "{0f4114c6-bf5a-4041-b737-6572ee1944df}",
  "name": "Developer PowerShell",
  "commandline": "pwsh.exe -NoExit -Command \"& { Import-Module 'C:\\\\Program Files (x86)\\\\Microsoft Visual Studio\\\\2022\\\\BuildTools\\\\Common7\\\\Tools\\\\Microsoft.VisualStudio.DevShell.dll'; Enter-VsDevShell -VsInstallPath 'C:\\\\Program Files (x86)\\\\Microsoft Visual Studio\\\\2022\\\\BuildTools' -DevCmdArguments '-arch=x64 -host_arch=x64' }\""
}

Notes

I recommend putting a function in your $Profile:

function Enter-DevShell {
    Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
    Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools" -DevCmdArguments "-arch=x64 -host_arch=x64"
}

Then the Terminal profile becomes much simpler:

{
  "guid": "{0f4114c6-bf5a-4041-b737-6572ee1944df}",
  "name": "Developer PowerShell",
  "commandline": "pwsh.exe -NoExit -Command Enter-DevShell"
}

Also note that pwsh.exe is from the Microsoft.PowerShell Winget package, and the UUIDs are from [guid]::NewGuid().

Extras

The build tools include nmake for running Makefiles. You can also install modern tooling:

winget install --source winget --id Kitware.CMake
winget install --source winget --id Ninja-build.Ninja

For debugging, use the VS Code extension or WinDbg.

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