【发布时间】:2019-04-17 22:05:05
【问题描述】:
我有一个模块,我叫它xyz.ps.core。它导出一个函数 - Get-PullRequestsFromCommitIds
我修复了函数中的一个错误,重新发布了模块,重新安装并重新导入了它,但该函数仍然引用了旧版本的模块。
请注意:
C:\xyz\tip [master ≡]> Get-Command Get-PullRequestsFromCommitIds | ft -AutoSize
CommandType Name Version Source
----------- ---- ------- ------
Function Get-PullRequestsFromCommitIds 1.0.19107.4 xyz.ps.core
如您所见,该功能来自版本1.0.19107.4
C:\xyz\tip [master ≡]> get-module xyz.ps.core | ft -AutoSize
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 1.0.19107.7 xyz.ps.core {Assert-ExtractionDestFolder, Assert-PullRequestMatchesFolder, Backup-Database, Connect-OctopusToTfs...}
C:\xyz\tip [master ≡]> get-module xyz.ps.core -ListAvailable | ft -AutoSize
Directory: C:\Users\mkharitonov\Documents\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 1.0.19107.7 xyz.PS.Core {Assert-ExtractionDestFolder, Assert-PullRequestMatchesFolder, Backup-Database, Connect-OctopusToTfs...}
但是模块版本已经在1.0.19107.7。但是好的,我有一个刷新模块的功能,即使它已经安装到相同的版本:
C:\xyz\tip [master ≡]> (get-command Use-Module).ScriptBlock
param([Parameter(Mandatory)]$Name)
if ($VerbosePreference -ne 'Continue')
{
Write-Host -ForegroundColor Cyan -NoNewline "Using the latest version of $Name ... "
}
Write-Verbose "Uninstalling all the versions of $Name ..."
Uninstall-Module $Name -AllVersions -Force -ErrorAction SilentlyContinue
Remove-Module $Name -Force -ErrorAction SilentlyContinue
Write-Verbose "Installing the latest version of $Name ..."
Install-Module $Name -Scope CurrentUser -Force
Write-Verbose "Importing $Name into the current session ..."
Import-Module $Name -Force
if ($VerbosePreference -ne 'Continue')
{
Write-Host -ForegroundColor Cyan (Get-Module $Name).Version
}
让我们现在使用它:
C:\xyz\tip [master ≡]> use-module xyz.ps.core
Using the latest version of xyz.ps.core ... 1.0.19107.7
让我们检查一下函数来源:
C:\xyz\tip [master ≡]> Get-Command Get-PullRequestsFromCommitIds | ft -AutoSize
CommandType Name Version Source
----------- ---- ------- ------
Function Get-PullRequestsFromCommitIds 1.0.19107.4 xyz.ps.core
还是旧的。请注意,在新的 Powershell 窗口中,该函数取自模块的当前版本。
是否可以在不关闭powershell的情况下刷新功能?
【问题讨论】:
-
你的意思是
Import-Module modulename -Force吗? -
我已经在这样做了 - 注意我用来刷新模块的函数
Use-Module中的Import-Module $Name -Force。
标签: powershell module powershell-module