我有一系列用 PowerShell(而不是 C#)编写的 PowerShell 模块,并且我在代码中包含文档注释,以便用户从 Get-Help 获得完整的 API 描述。
当我编写一个新模块时,帮助文本似乎在某个时间点被卡住了;在保存文件、重新导入模块、甚至重新启动 PowerShell 然后重新导入模块后,我对该文件中的帮助文本所做的任何后续更新都没有显示。
接下来我创建了一个测试模块,看看是否可以复制该问题。我设置了 psm1 和 psd1 文件,导入了模块,然后运行 get-help,从 psm1 文件中查看帮助。然后,我向 psm1 文件添加一行文本,保存它,重新导入它......新行出现在 get-help 中!
我依稀记得前段时间读过,您必须更改 psd1 文件中的版本才能识别新的帮助,但我的测试用例表明不一定需要(而且我真的不想更改版本) )。
我还隐约记得读过导入的模块缓存在某处,只需删除缓存的文件即可使其识别新文本 - 但我不记得在哪里可以找到这些文件。
所以我的目标是能够在我的真实模块中看到保存在 psm1 文件中的修改后的帮助文本,而无需增加模块版本。有想法吗?
最佳答案
在重命名和更新某些模块中的函数时,我遇到了类似的问题。搜索了一下发现了http://www.powertheshell.com/how-module-command-discovery-works-in-psv3/ 。特别是,最后一点关于过时的缓存提到
PS> Get-Module -ListAvailable -Refresh
运行解决了我的缓存问题
PS> Get-Help Get-Module -Parameter Refresh
-Refresh [<SwitchParameter>]
Refreshes the cache of installed commands. The command cache is created when the session starts. It enables
the Get-Command cmdlet to get commands from modules that are not imported into the session.
This parameter is designed for development and testing scenarios in which the contents of modules have
changed since the session started.
When the Refresh parameter is used in a command, the ListAvailable parameter is required.
关于caching - 对 PowerShell 中的 PowerShell 模块编写帮助进行故障排除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16270425/