我正在尝试在 Windows Server 2019 上将 PowerShellGet 从 1.0.0.1 版本升级到较新版本。我不是 NuGet 专家,但对包提供程序和包源有基本的了解。我一直在遵循Microsoft Learn 网站上的这个指南和这个指南以及其他指南。我位于公司防火墙后面,无法访问常规互联网。我们有一个Nexus实例,其中配置了以下存储库:
- Nuget 代理名为 psgallery-proxy,网址为https://www.powershellgallery.com/api/v2/
- Nuget 代理名为 nugetorg-proxy,网址为https://www.nuget.org/api/v2/
首先,我将 NuGet 提供程序版本 2.8.5.208 从另一台计算机复制到$env:ProgramFiles\PackageManagement\ProviderAssemblies\NuGet\2.8.5.208
。然后在 Powershell 中执行了以下步骤:
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
Import-PackageProvider -Name NuGet -RequiredVersion 2.8.5.208
$cred = Get-Credential
Register-PackageSource -Name NexusNugetOrg -ProviderName Nuget -Location https://example.com/repository/nugetorg-proxy/ -Trusted -Credential $cred
Register-PSRepository -Name NexusPSGallery -SourceLocation https://example.com/repository/psgallery-proxy/ -InstallationPolicy Trusted -Credential $cred
运行这些命令后,我得到以下内容,在我看来这是正确的:
PS C:\Windows\system32> Get-PackageProvider -ListAvailable
Name Version DynamicOptions
---- ------- --------------
msi 3.0.0.0 AdditionalArguments
msu 3.0.0.0
NuGet 2.8.5.208 Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag, Contains, AllowPrereleaseVersions, ConfigFile, SkipValidate
PowerShellGet 1.0.0.1 PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, InstallUpdate, NoPathUpdate, Filter, Tag, Includes, DscResource, RoleCapability, Command, PublishLocation, ScriptSourceLocation, ScriptPublishLocation
Programs 3.0.0.0 IncludeWindowsInstaller, IncludeSystemComponent
PS C:\Windows\system32> Get-PackageSource
Name ProviderName IsTrusted Location
---- ------------ --------- --------
NexusNugetOrg NuGet True https://example.com/repository/nugetorg-proxy/
NexusPSGallery PowerShellGet True https://example.com/repository/psgallery-proxy/
PS C:\Windows\system32> (Get-ItemPropertyValue -LiteralPath 'HKLM:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' -Name Release) -ge 394802
True
我可以安装普通软件包。如果我运行以下命令,模块安装成功,并且我可以dbatools
在 Nexus 中看到它:
Install-Module -Name dbatools -Force -Credential $cred -Repository NexusPSGallery
但是,我无法升级 PowerShellGet。我得到以下输出:
PS C:\Windows\system32> Install-Module -Name PowerShellGet -Force -AllowClobber -Credential $cred -Repository NexusNugetOrg
PackageManagement\Get-PackageSource : Unable to find repository 'NexusNugetOrg'. Use Get-PSRepository to see all available repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:4489 char:35
+ ... ckageSources = PackageManagement\Get-PackageSource @PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power...etPackageSource:GetPackageSource) [Get-PackageSource], Exception
+ FullyQualifiedErrorId : SourceNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageSource
PS C:\Windows\system32> Install-Module -Name PowerShellGet -Force -AllowClobber -Credential $cred -Repository NexusPSGallery
PackageManagement\Install-Package : No match was found for the specified search criteria and module name 'PowerShellGet'. Try Get-PSRepository to see all available registered module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1809 char:21
+ ... $null = PackageManagement\Install-Package @PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
我缺少什么才能成功运行 Install-Module PowerShellGet?
最后,我将模块从安装了较新版本 Windows 的 PC 复制到目标机器。
C:\Program Files\PackageManagement\ProviderAssemblies\NuGet
C:\Program Files\WindowsPowerShell\Modules\PowerShellGet
然后我按如下方式注册了 NuGet 提供程序:
并启用 Powershell Gallery 镜像: