visual-studio-code - 默认 Powershell 终端为 7.2,但脚本以 Powershell 5.1 运行

标签 visual-studio-code powershell-7.0 powershell-7.2

请注意,在我的 VS Code 中,一个新的终端,第一行表明它已正确默认为 Powershell 7.2.2 - 正如我认为应该的那样。

但在同一张屏幕截图中,我运行的第一个脚本(其中有一个打印 powershell 版本的命令)显示 PSVersion5.1.19041.1320

vs code default terminal screenshot

这是来自 settings.json 的所有 powershell 特定 VSCode 条目

    "terminal.integrated.profiles.windows": {
        "MyPowerShell_7": {
          "path": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
          "args": ["-NoProfile"]
        }
    },
    "terminal.integrated.defaultProfile.windows": "MyPowerShell_7",
    "powershell.powerShellAdditionalExePaths": [
        {
            "exePath": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
            "versionName": "MyPowerShell_7"
        }
    ],
    "powershell.powerShellDefaultVersion": "MyPowerShell_7",

为什么运行 Test-Json cmdlet 这么困难?

最佳答案

终于找到答案了here on reddit

我不知道 5.1 和 7 是并行的并且有不同的方式来调用每个应用程序

因此,如果我将命令从 powershell 更改为 pwsh,我会得到正确的结果

enter image description here

关于visual-studio-code - 默认 Powershell 终端为 7.2,但脚本以 Powershell 5.1 运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71769124/

相关文章:

javascript - 为什么 Prettier 不格式化 VS Code 中的代码?

c# - 在 PowerShell 中隐式转换为 C# 中定义的结构的 bool 失败

azure-powershell - PowerShell 7. ForEach-Object -Parallel 不会针对 Azure PowerShell 进行身份验证

powershell - 从命令行 PowerShell 7.2 传递哈希表参数

visual-studio-code - Visual Studio 代码 : "Open Recent" does not have a file I opened in last session

c++ - 运行几次后 Vscode 自动格式代码停止工作

powershell - Foreach 对象并行 block 中的错误处理 - Powershell 7

.net - PowerShell - 尝试在没有自签名证书问题的情况下进行 REST 调用的添加类型问题

c++ - Visual Studio Code 在调试时使用输入文本文件