Skip to main content

Hack: Running Visual Studio Developer Powershell inside vscode

· 2 min read
Quentin Faidide

I recently tried to port a software to Windows, and some dependencies required the Microsoft Visual Studio C++ compiler. I therefore needed to use their version of cmake, vcpkg and ninja. I figured out that the best way to interract with these tools was through the Visual Studio Developer Powershell console. As I don't like Visual Studio, I figured out how to run its terminal inside vscode and will share the hack here.

This is a quick tutorial on how to run the visual studio developer powershell inside visual studio code. You ovbiously need both softwares installed.

Creating a new visual studio code profile

In vscode, type CTRL+SHIFT+P to open the command search utility and select Preferences: Open User Settings (JSON).

You should then add the following section, replacing the Visual Studio path with yours:

{
"terminal.integrated.defaultProfile.windows": "Windows PowerShell",
"terminal.integrated.profiles.windows": {
"Visual Studio Developer Shell": {
"path": [
"C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
],
"args": [
"-NoExit",
"-Command",
"Import-Module \"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\Tools\\Microsoft.VisualStudio.DevShell.dll\"; Enter-VsDevShell -SkipAutomaticLocation -SetDefaultWindowTitle -InstallPath \"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\\""
],
"icon": "terminal-cmd"
}
}
}
warning

You are likely to want to have the x64 architecture as target. In that eventuality, you should add -DevCmdArguments \"-arch=x64 -no_logo\" as command line argument to Enter-VsDevShell the following way:

{
"terminal.integrated.defaultProfile.windows": "Windows PowerShell",
"terminal.integrated.profiles.windows": {
"Visual Studio Developer Shell (x64)": {
"path": [
"C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
],
"args": [
"-NoExit",
"-Command",
"Import-Module \"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\Tools\\Microsoft.VisualStudio.DevShell.dll\"; Enter-VsDevShell -SkipAutomaticLocation -SetDefaultWindowTitle -InstallPath \"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\\" -DevCmdArguments \"-arch=x64 -no_logo\""
],
"icon": "terminal-cmd"
}
}
}

You're done

Save your file, and select your new terminal profile inside vscode, and you should have access to the Visual Studio shell inside vscode!