我刚刚安装了 PowerShell 7,由于我之前安装了 anaconda,这似乎会自动将启动命令添加到 profile.ps1。
C:\Users\USER\Documents\PowerShell 中的 profile.ps1(这是版本 7,目录 WindowsPowerShell 将是旧版本 5)包含:
#region conda initialize
# !! Contents within this block are managed by 'conda init' !!
(& "C:\Users\USER\anaconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | Invoke-Expression
#endregion
通过 PowerShell 7 启动时的这些自动设置,将 PowerShell 7 作为新的终端类型添加到 vsccode 解决了这个问题。
这是将 PowerShell 7 添加到下拉菜单的方法:
输入Ctrl+Shift+P,为用户打开settings.json,添加
{
"terminal.integrated.profiles.windows": {
"PowerShell7": {
"path": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
"args": ["-NoProfile",
"-noexit",
"-file",
"C:\\Users\\USER\\Documents\\PowerShell\\profile.ps1"]
}
},
"terminal.integrated.defaultProfile.windows": "PowerShell7"
}
然后在 settings.json 中,按 Ctrl+s 并重新启动 (!) vscode。您将在终端类型下拉列表中看到 PowerShell7 作为新的默认终端: