繁体   English   中英

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

[英]Cannot debug PowerShell scripts in Visual Studio Code

我将使用 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}"
}

如何使用 F5 进行调试?

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

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

会话退出警告

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

这是在 launch.json 中的以下配置(在 Windows 10 机器上):

{
    "name": "PowerShell: Launch script.ps1",
    "type": "PowerShell",
    "request": "launch",
    "script": ".\\script.ps1",
    "cwd": "${workspaceFolder}"
}

要解决此问题,您可以尝试通过以下方式重新启动当前的 PowerShell 会话:

  1. 打开命令托盘( command + shift + p
  2. 搜索重新启动当前会话并选择它
  3. 再次按下F5

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

如果您的 PackageManagement 模块不是最新的,则可能会弹出此错误消息,VSCode 会接收到该错误消息,在屏幕右下方显示一个弹出窗口,询问您是否要更新并且在更新之前不考虑 Powershell 已启动被解雇。

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

Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Install-Module -Name PackageManagement -Force -MinimumVersion 1.4.6 -Scope CurrentUser -AllowClobber -Repository PSGallery

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM