【问题标题】:Visual Studio Code issue with displaying message boxes显示消息框的 Visual Studio Code 问题
【发布时间】:2020-08-27 16:14:24
【问题描述】:

我正在尝试显示一个消息框并且在 ISE/Powershell 中没有问题;但是,当我在 Visual Studio Code 中运行时,会出现此错误:

Line |
  12 |  $user = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Method invocation failed because [Microsoft.VisualBasic.Interaction] does not contain a method named 'InputBox'.

我已将 Powershell 扩展添加到 VS Code。看来我仍然缺少一些东西,但我不确定是什么。

有什么想法吗?

【问题讨论】:

    标签: powershell visual-studio-code


    【解决方案1】:

    这意味着您的 PowerShell 扩展(PowerShell 集成控制台)使用 PowerShell [Core] 最高版本 7.0,该版本基于 .NET Core 3.1,其中 [Microsoft.VisualBasic.Interaction]::InputBox() method isn't available 为 @ 987654322@指出。

    在即将发布的基于 .NET 5 的 PowerShell [Core] 7.1 版中,will become available again

    配置要使用的 PowerShell 扩展:

    • 任一:Windows PowerShell,预装在任何 Windows 机器上。

      • 请注意,您必须在调用该方法之前调用Add-Type -AssemblyName Microsoft.VisualBasic
    • 或者:目前,虽然 PowerShell [Core] 7.1 尚不可用,但请使用最新的 v7.1 preview 版本,here,它基于 .NET 5 预览版构建,其中该方法已经可用。

    请参阅this answer 的底部,了解如何配置 PowerShell 扩展以使用特定的 PowerShell 版本。

    【讨论】:

    • 逗号做到了!非常感谢您的帮助!
    • 如果您不介意,再问一个问题。我试图在我的 Mac(我实际首选的系统)上复制它,并且我将其全部设置为指向 7.1 等,就像你在 Windows 上向我展示的那样。但我仍然遇到同样的错误。 Mac 有什么特别之处吗?
    • 唯一的区别应该是:使用/作为路径分隔符并且加倍(虽然这样做实际上应该是良性的)。
    猜你喜欢
    • 1970-01-01
    • 2022-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-07
    • 1970-01-01
    • 2022-01-24
    • 1970-01-01
    相关资源
    最近更新 更多