【问题标题】:How can you reset the PowerShell runspace within Visual Studio Code如何在 Visual Studio Code 中重置 PowerShell 运行空间
【发布时间】:2017-08-08 08:14:13
【问题描述】:

我目前在 Visual Studio Code 中使用 0.10.0 版的 PowerShell 扩展。过去,每次运行脚本之间都会重置运行空间,因此如果对模块进行了更改,则会将更新的模块导入脚本中。

但是,由于某种原因,PowerShell 运行空间不再被重置,因此在下次运行期间不会获取模块中的更改。

PowerShell 扩展中是否有一个设置可以确保在每次运行脚本之间重置运行空间?

【问题讨论】:

    标签: powershell visual-studio-code powershell-3.0


    【解决方案1】:

    对此我仍然没有一个好的答案,但这是我在开发过程中为缓解问题所做的。

    我注意到 VS Code 会在每次运行之间缓存变量,并且它可以像 REPL 一样有效地运行脚本。

    由于 PowerShell 作用域的性质,您可以将代码包装在 Invoke-Command -ScriptBlock {} 中,并且由于在其脚本块之外无法访问变量,您可以重新运行代码而不必担心将对象留在 vs 代码中。

    【讨论】:

      【解决方案2】:

      现在可在 Visual Studio Code 的 PowerShell 插件中使用的设置 powershell.debugging.createTemporaryIntegratedConsole 解决了我的问题。

      该设置默认为 false,因此必须先启用它才能起作用。

      当它设置为 true 时,每次尝试通过脚本进行调试时都会重置 PowerShell 会话。这意味着:

      • 可以重置常量变量
      • PowerShell 模块的更新将被拉入会话中

      可以通过在用户设置 JSON 文件中添加以下行来启用它

      "powershell.debugging.createTemporaryIntegratedConsole": true
      

      或者在 File -> Preferences -> Settings 下的 Preferences 中启用它并搜索 Create Temporary Integrated Console

      【讨论】:

      猜你喜欢
      • 2018-02-26
      • 1970-01-01
      • 2022-12-16
      • 1970-01-01
      • 2019-07-31
      • 2016-07-06
      • 1970-01-01
      • 1970-01-01
      • 2020-01-02
      相关资源
      最近更新 更多