Lar*_*Cai 10 powershell visual-studio-code
我正在尝试在 Windows 11 上将默认的 Powershell 5 替换为较新的 Powershell 7。
互联网上 99% 的解决方案都说要将其添加到settings.json.
"terminal.integrated.shell.windows": "C:\\Program Files\\PowerShell\\7\\pwsh.exe"
Run Code Online (Sandbox Code Playgroud)
但是,现在会显示一条红色波浪线,并显示以下消息:
这已被弃用,配置默认 shell 的新推荐方法是在 中创建终端配置文件
#terminal.integrated.profiles.windows#并将其配置文件名称设置为 中的默认值#terminal.integrated.defaultProfile.windows#。目前,这将优先于新的配置文件设置,但将来会发生变化。(2)
有一个可能相关的线程,但它只处理将其默认为本地线程Command Prompt,而不是重新调整事物Powershell 7。
那么,向 VS Code 提供Powershell 7路径并将其设置为默认终端的正确新方法是什么?
mkl*_*nt0 22
前言:
下面的解决方案解决了所提出的问题,涉及settings.json文件的修改。
然而,现在有一个GUI方法可以让您更方便地选择默认配置文件,假设您的PowerShell 7+安装位于 Visual Studio Code 已知的标准位置 - 请参阅Lee Grissom 的回答。
但是,对于 Visual Studio Code 无法自动发现的安装或自定义现有配置文件的启动选项,您仍然需要该settings.json方法。
这两种方法都涉及使用 PowerShell 7 作为Visual Studio Code 集成终端中的默认通用shell。
在早期的VSCode (Visual Studio Code) 版本中,"terminal.integrated.shell.*"和"terminal.integrated.shellArgs.*"设置确定集成终端的默认 shell 及其启动参数。
这些已被shell配置文件取代,通过属性和包含默认使用的配置文件名称"terminal.integrated.profiles.*"的关联属性定义,如下所示。"terminal.integrated.defaultProfile.*"
// Excerpt from settings.json
"terminal.integrated.profiles.windows": {
    "PowerShell_7": {
      "path": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
      "icon": "terminal-powershell"
    },  // ...
}
// Make the profile defined above the default profile.
"terminal.integrated.defaultProfile.windows": "PowerShell_7" 
Run Code Online (Sandbox Code Playgroud)
笔记:
打开settings.json文件进行编辑,如下所示: 从命令选项板(选择菜单命令View>Command Palette...或按Ctrl+Shift+P),选择命令Preferences: Open User Settings (JSON);搜索user json应该足以找到它。
我希望 Visual Studio Code自动使用您的 v7 版本,因为它(如果已安装)通常优先于 Windows PowerShell。
|   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           13766 次  |  
        
|   最近记录:  |