Powershell 强制重新加载以使用模块

Powershell forcing reload for using module

有没有办法强制 PowerShell 在 using module .\MyModule.psm1 时重新加载模块?

通常我会使用 Import-Module .\MyModule.psm1 -Force 但因为我使用的是 enumclass C# 风格,所以这行不通;因为 enumclass 在模块外不可见,如果我使用 Import-Module.

我不能先使用 Import-Module,然后再使用 using module,因为 using module 必须在第一行。

我的 PSVersion 是 5.1.14409.1005

恐怕目前还没有解决方案(从 Windows PowerShell v5.1 / PowerShell Core 7.2 开始),但是正在为 PowerShell Core 提出一个解决方案在 GitHub issue #7654.

此外,根据您自己的观察,相关问题...

includes further links with discussion, uservoice item and comments about difference between PS and PSCore and some more comments about using vs Import-Module language-design wise.