我有各种用PowerShell编写的PowerShell模块(而不是C#),我在代码中包含了文档注释,以便用户从Get-Help获得完整的API描述。
当我写一个新模块时,帮助文本似乎在某个时间点卡住;在保存文件,重新导入模块,甚至重新启动PowerShell然后重新导入模块后,我对该文件中的帮助文本所做的任何后续更新都显示 not 。
我接下来创建了一个测试模块,看看我是否可以复制该问题。我设置了psm1和psd1文件,导入了模块,并运行了get-help,看到了psm1文件的帮助。然后我在psm1文件中添加了一行文本,将其保存,重新导入...并且新行显示在get-help中!
我模糊地回忆起前段时间读过你必须碰到psd1文件中的版本以获得新的帮助才能被识别,但我的测试用例表明不一定需要(我真的不想碰到版本)。
我还隐约记得读过导入的模块在某处缓存,可以删除缓存的文件以使其识别新文本 - 但我不记得在哪里找到它们。
所以我的目标是能够在我的实际模块中看到保存在psm1文件中的修订帮助文本,而无需增加模块版本。想法?
答案 0 :(得分:4)
在我的某些模块中重命名和更新函数时,我遇到了类似的问题。有点搜索出现了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.
答案 1 :(得分:1)
如果导入已导入的模块,则不会替换先前导入的功能。您需要先使用Remove-Module删除模块,然后再次导入。我发现在我的个人资料中使用此功能很方便:
function reload {
param(
[parameter(Mandatory=$true)]$Module
)
Write-Host;
try {
Remove-Module $Module -ea Stop;
} catch {
Write-Warning $error[0].Exception.Message;
Write-Host;
} finally {
Import-Module $Module -Verbose;
}
Write-Host;
}