无法在 Visual Studio Code 中调试 PowerShell 脚本

Ger*_*ely 6 powershell visual-studio-code vscode-debugger

我将使用 F5 在 Visual Studio Code 中运行 PowerShell 脚本。

我的 Visual Studio Code 版本是 1.50.1,提交 d2e414d9e42

我收到以下错误消息:

在 PowerShell 会话启动之前,无法调试或运行 PowerShell 脚本。等待 PowerShell 会话完成启动并重试。

我安装了官方的 Microsoft PowerShell 扩展,我的 launch.json 包括以下内容:

{
        "name": "PowerShell: Launch Script",
        "type": "PowerShell",
        "request": "launch",
        "script": "countcharacters.ps1",
        "cwd": "${workspaceFolder}"
}
Run Code Online (Sandbox Code Playgroud)

如何使用 F5 进行调试?

Jus*_*tin 18

To solve this problem, you can try to restart your current PowerShell session by:

  1. Opening the command pallet (command+shift+p)
  2. Searching for Restart Current Session and selecting it
  3. F5再次按下按钮

您可能会再次看到该问题弹出,但只需F5再次按一下,您就会看到事情开始执行。


dav*_*ats 6

在按 F5 之前关闭所有打开的 PowerShell 窗口为我解决了这个问题。

您可能还需要确保没有此会话退出警告:

会话退出警告

如果这样做,请单击“重新启动当前会话”,然后尝试再次按 F5。 重新启动当前会话选项

这是在 launch.json 中使用以下配置(在 Windows 10 计算机上):

{
    "name": "PowerShell: Launch script.ps1",
    "type": "PowerShell",
    "request": "launch",
    "script": ".\\script.ps1",
    "cwd": "${workspaceFolder}"
}
Run Code Online (Sandbox Code Playgroud)


Dej*_*489 5

安装最新版本的包管理,然后重新启动 PowerShell 会话或 VSCode 解决了该问题。

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Install-Module -Name PackageManagement -Force -MinimumVersion 1.4.6 -Scope CurrentUser -AllowClobber -Repository PSGallery
Run Code Online (Sandbox Code Playgroud)