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.
Install Visual Studio Build Tools via Winget:
winget install --source winget --id Microsoft.VisualStudio.2022.BuildToolsRun 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.
Load the developer environment:
"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\VsDevCmd.bat" -arch=x64 -host_arch=x64{
"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\""
}%ComSpec%is the environment variable forcmd.exe./kruns the command and keeps the shell open (interactive)./cwould have run the command and exited (non-interactive).
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"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' }\""
}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().
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