Estou tentando atualizar o PowerShellGet da versão 1.0.0.1 para uma versão mais recente no Windows Server 2019. Não sou especialista em NuGet, mas tenho um conhecimento básico de provedores e fontes de pacotes. Tenho seguido este e este guia no site Microsoft Learn, além de outros. Estou protegido por um firewall corporativo e não consigo acessar a internet em geral. Temos uma instância do Nexus com os seguintes repositórios configurados:
- Proxy NuGet chamado psgallery-proxy de https://www.powershellgallery.com/api/v2/
- Proxy NuGet chamado nugetorg-proxy de https://www.nuget.org/api/v2/
Primeiro, copiei a versão 2.8.5.208 do provedor NuGet de outro computador para o $env:ProgramFiles\PackageManagement\ProviderAssemblies\NuGet\2.8.5.208
. Depois, executei os seguintes passos no 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
Depois de executar esses comandos, recebo o seguinte, que me parece estar correto:
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
Consigo instalar pacotes normais. Se eu executar o seguinte comando, a instalação do módulo será bem-sucedida e posso ver que ele dbatools
aparece no Nexus:
Install-Module -Name dbatools -Force -Credential $cred -Repository NexusPSGallery
No entanto, não consigo atualizar o PowerShellGet. Recebo a seguinte saída:
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
O que estou perdendo para conseguir executar com sucesso o Install-Module PowerShellGet?