I'm working on a project that requires me to compile C++ code using MSVC, but I am working mostly with VSCode. As such, I was wondering if there is a way for me to add the Developer Powershell as an integrated terminal, so that I can compile without needing a secondary terminal open. I thought of just opening VSCode from the Developer PS itself, but since this is mostly a temporary project it seemed like a lot of repetitive work. I tried using the Shell launcher
extension for VSCode but it didn't work. Is there anything I can do?
Update:
The answer below is obsolete. For a current solution, see Elon Mallin's answer, for instance, which uses the dedicated Launch-VsDevShell.ps1.ps1
script that has since been introduced, and shows a JSON object that you can place inside the "terminal.integrated.profiles.windows"
property in settings.json
(create the property if not already present), which makes a shell named Developer PowerShell for VS 2022
available in the integrated terminal.
That said, there are some subtleties to consider, and no single answer addresses them all as of this writing; a robust formulation[1] requires the following; note that the Launch-VsDevShell.ps1
script's path changes between Visual Studio versions, and varies based on whether a given installation is 32-bit vs. 64-bit as well as the edition name (Community, Professional, ...) the following hard-codes the path for the Professional edition of Visual Studio 2022 - adjust as needed:
// 'settings.json' excerpt
// (Open the file via the command palette with
// "Preferences: Open User Settings (JSON)"):
// Create this property, if necessary; if it already exists,
// add the nested "Developer PowerShell for VS 2022 Professional"
// property as a new property to it.
"terminal.integrated.profiles.windows": {
// Preexisting profiles, if any...
"Developer PowerShell for VS 2022 Professional": {
"overrideName": true,
"source": "PowerShell",
"icon": "terminal-powershell",
"args": [
"-NoExit",
"-File",
"C:/Program Files/Microsoft Visual Studio/2022/Professional/Common7/Tools/Launch-VsDevShell.ps1",
"-SkipAutomaticLocation"
]
}
}
Obsolete, original answer:
To make Visual Studio Code's integrated terminal act like the Developer PowerShell for VS 2019
console that comes with Visual Studio 2019, add the following to your Visual Studio Code settings.json
file (> Preferences: Open Settings (JSON)
):
"terminal.integrated.shell.windows": "C:/Windows/SysWOW64/WindowsPowerShell/v1.0/powershell.exe"
and
"terminal.integrated.shellArgs.windows": "-noe -c Import-Module 'C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/Tools/Microsoft.VisualStudio.DevShell.dll'; Enter-VsDevShell ed9e071d"
Note that a 32-bit version of PowerShell is started, followed by import of a module and a call to a function from that module.
I've taken (and adapted) the commands - whose details may differ depending on the Visual Studio version - from the Properties dialog of the following shortcut file (*.lnk
):
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2019\Visual Studio Tools\Developer PowerShell for VS 2019.lnk
[1] For robustness, the -File
parameter of the PowerShell CLI must be used; without -File
, it only works if you happen to have the install-on-demand PowerShell (Core) 7 edition of PowerShell installed, whose CLI (pwsh.exe
) now defaults to the -File parameter. By contrast, the ships-with-Windows , legacy Windows PowerShell edition (whose CLI is powershell.exe
), -Command
is implied, which breaks calling a script path that contains spaces. Visual Studio Code, with a "source"
property value of "PowerShell"
, uses PowerShell (Core) 7 if found installed, and Windows PowerShell otherwise.
As for the working directory: Launch-VsDevShell.ps1
sets its own working directory, unless suppressed via -SkipAutomaticLocation
. Thus, -SkipAutomaticLocation
must be passed in order for the Visual Studio Code-determined working directory to take effect.
Optionally - in PowerShell (Core) 7 only - you may control the working dir. via the PowerShell CLI's -WorkingDirectory
parameter, but note that passing ${workspacefolder}
only works if Visual Studio Code was given a folder or workspace argument on startup.
Finally, if you wanted to control the working directory via Windows PowerShell, you'd have to switch to a -Command
-based CLI call that uses an in-session Set-Location
(cd
) call.