Visual Studio Code 集成终端默认为 PowerShell Core

Kee*_*tle 2 terminal powershell visual-studio-code

我最近安装了PowerShell Core v6。我想检查一下,看看它是什么样的,如果我想玩它,可以很容易地切换到Windows 终端。安装版本 6 后,Visual Studio Code 继续使用集成控制台的核心,尽管我的settings.json文件指向System32中的powershell.exe文件。我怎样才能解决这个问题?

我们的环境全部使用 5.1 版本,核心缺少 5.1 中的许多功能和 cmdlet。在测试我将部署的脚本时我需要这些。我可以添加另一个终端,它将使用 PowerShell 5.1,但由于它未集成,运行脚本块有时会失败。这是我的settings.json文件:

{
    "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
    "window.zoomLevel": 0,
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "explorer.confirmDragAndDrop": false,
    "files.autoSave": "afterDelay",
    "powershell.powerShellDefaultVersion": "Windows Powershell (x64)",
    "editor.accessibilitySupport": "off"
}
Run Code Online (Sandbox Code Playgroud)

mkl*_*nt0 6

"terminal.integrated.shell.windows"适用于不特定于任何特定开发语言的集成通用终端。

您正在寻找"powershell.powerShellExePath" 特定于Visual Code 的 PowerShell 扩展的设置,并确定将哪个 PowerShell 可执行文件用于所谓的PowerShell 集成控制台(PIC),该控制台为 PowerShell 开发和调试提供特殊功能。

更新:该powershell.powerShellExePath设置现已弃用

  • 有关当前解决方案,请参阅本答案的底部部分,其中描述了settings.json控制 PIC 中使用的 PowerShell 版本的方法和 GUI 方法。

原来的,现在已经过时的答案:

因此,要使 PowerShell 集成控制台运行 Windows PowerShell,请使用:

"powershell.powerShellExePath": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
Run Code Online (Sandbox Code Playgroud)

注意:第一次在会话中激活编辑器选项卡(其中加载了包含 PowerShell 代码的文件)时,PowerShell 集成控制台将被加载并保持活动状态,即使您切换到非 PowerShell 编辑器选项卡也是如此。

使用终端面板右上角的弹出列表在正在运行的 shell 之间切换,例如,为了返回到集成终端的 shell:

运行外壳