To build projects using the MSVC compiler (cl.exe), CMake, and Ninja directly from the Visual Studio Code interface, you need to add the Visual Studio environment profiles to the built-in terminal.
Step-by-Step Instructions
- Open the settings.json configuration file:
- Press Ctrl + Shift + P.
- Type Preferences: Open User Settings (JSON) into the search bar and press Enter.
- Add the profile configuration:
Insert the following block of settings inside the main curly braces { … } of your settings.json file:
"terminal.integrated.profiles.windows": {
"Developer PowerShell (x64)": {
"source": "PowerShell",
"overrideName": true,
"args": [
"-NoExit",
"-Command",
"& { Import-Module 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\Tools\\Microsoft.VisualStudio.DevShell.dll'; Enter-VsDevShell 43240475 -SkipAutomaticLocation -DevCmdArguments '-arch=x64' }"
]
},
"Developer PowerShell (x86)": {
"path": "C:\\Windows\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe",
"overrideName": true,
"args": [
"-NoExit",
"-Command",
"& { Import-Module 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\Tools\\Microsoft.VisualStudio.DevShell.dll'; Enter-VsDevShell 43240475 -SkipAutomaticLocation }"
]
}
}
(Note: The paths are specified for a standard Visual Studio 2022 Community installation. If you are using Professional or Enterprise editions, replace Community in the paths with the corresponding name).
- Apply the settings:
- Save the settings.json file.
- Close active terminal sessions in VS Code using the trash can icon (Kill Terminal) in the terminal panel to refresh the profile list.
- Launch the terminals:
- Click the arrow next to the “plus” sign in the upper-right corner of the terminal panel.
- Select the required architecture from the dropdown list: Developer PowerShell (x64) or Developer PowerShell (x86).