如何在Visual Studio Code中重置PowerShell运行空间

ger*_*ard 4 powershell powershell-3.0 visual-studio-code

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

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

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

ger*_*ard 7

powershell.debugging.createTemporaryIntegratedConsole现在,Visual Studio Code的PowerShell插件中提供的设置解决了我的问题。

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

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

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

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

"powershell.debugging.createTemporaryIntegratedConsole": true
Run Code Online (Sandbox Code Playgroud)

或者在“文件”->“首选项”->“设置”下的“首选项”中启用它,然后搜索“创建临时集成控制台”

  • 不幸的是,“TemporaryIntegratedConsole”有一个 1 1/2 年来未修复的错误,它阻止了交互式调试脚本。https://github.com/PowerShell/vscode-powershell/issues/1263 (2认同)