You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VSCode打开PowerShell文件为何用5.1而非Core?如何配置默认用6版?

解决VSCode打开.ps1文件默认用PowerShell 6的配置方案

我来帮你搞定这个问题——其实你遇到的核心差异是:VSCode的普通终端配置和PowerShell扩展自带的Integrated Console是两套独立的设置,咱们只需要调整扩展的配置就能统一用PowerShell 6啦,一步步来:

1. 让PowerShell扩展默认使用PowerShell 6(Core)

这是解决Integrated Console自动开5.1的关键:

  • 打开VSCode设置(快捷键Ctrl+,,或者通过菜单栏File > Preferences > Settings进入)
  • 在搜索框输入 powershell.powerShellExePath
  • 把对应的路径值设置为你的PowerShell 6可执行文件路径:
    "powershell.powerShellExePath": "C:\\Program Files (x86)\\PowerShell\\6\\pwsh.exe"
    
  • 保存设置后,下次打开.ps1文件时,PowerShell Integrated Console就会自动用6版本启动了

2. 确保调试时使用PowerShell 6

默认情况下,扩展会复用上面的exe路径,但保险起见可以检查调试配置:

  • 打开调试面板(快捷键Ctrl+Shift+D),点击「创建launch.json文件」并选择PowerShell
  • 在生成的launch.json中,确认runtimeExecutable字段指向你的pwsh.exe,示例配置如下:
    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "PowerShell: Launch Script",
                "type": "PowerShell",
                "request": "launch",
                "script": "${file}",
                "args": [],
                "runtimeExecutable": "C:\\Program Files (x86)\\PowerShell\\6\\pwsh.exe"
            }
        ]
    }
    
  • 这样调试脚本时就会强制使用PowerShell 6,不会再 fallback 到5.1了

3. 可选:关闭自动启动PowerShell Integrated Console

如果你更习惯用普通终端而非扩展的Integrated Console,可以额外设置:

  • 在设置中搜索 powershell.integratedConsole.showOnStartup
  • 将其值设为 false
  • 之后打开.ps1文件时,只会启动你之前配置的普通pwsh终端

设置完成后重启VSCode,再打开.ps1文件测试一下——不管是终端还是调试,都应该默认用PowerShell 6了,不用再手动敲命令啦。

内容的提问来源于stack exchange,提问作者jmoreno

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 07:55:36