I am trying to replace the default Powershell 5 with the newer Powershell 7, on Windows 11.
99% of the solutions on the internet say to add this to settings.json
.
"terminal.integrated.shell.windows": "C:\\Program Files\\PowerShell\\7\\pwsh.exe"
However, this now gives a red squiggly line with the following message:
This is deprecated, the new recommended way to configure your default shell is by creating a terminal profile in
#terminal.integrated.profiles.windows#
and setting its profile name as the default in#terminal.integrated.defaultProfile.windows#
. This will currently take priority over the new profiles settings but that will change in the future.(2)
There is one possibly related thread, but it only deals with defaulting it to the native Command Prompt
, rather than re-jigging things to Powershell 7
.
So, what is the correct new way to provide Powershell 7
s path to VS Code, and also set it as the default terminal?
CodePudding user response:
In earlier VSCode (Visual Studio Code) versions, the "terminal.integrated.shell.*"
and "terminal.integrated.shellArgs.*"
settings determined the default shell and its startup arguments for the integrated terminal.
These have been superseded by shell profiles, defined via "terminal.integrated.profiles.*"
properties, and an associated "terminal.integrated.defaultProfile.*"
property that contains the name of the profile to use by default, as shown below (use > Preferences: Open Settings (JSON)
from the command palette to open your settings.json
file):
"terminal.integrated.profiles.windows": {
"PowerShell_7": {
"source": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
"icon": "terminal-powershell"
}, // ...
}
// Make the profile defined above the default profile.
"terminal.integrated.defaultProfile.windows": "PowerShell_7"
Note:
The above defines the default general-purpose shell for Visual Studio Code's integrated terminal.
For information on how to specify what PowerShell version to use with the special-purpose PIC (PowerShell Integrated Console) that comes with the PowerShell extension (for authoring and debugging PowerShell code), see this answer.
I would have expected Visual Studio Code to use your v7 version automatically, as it - if installed - normally takes precedence over Windows PowerShell.