PowerShell / PowerShellGallery

228 stars 65 forks source link

NuGet 📦 PackageProvider "No match was found" #86

Closed mil1i closed 4 years ago

mil1i commented 4 years ago

Has something happened where the NuGet package provider is missing now?

This is failing to install in pipelines, as well as locally for multiple people on my team (working from different locations).

Now from the examples below, you'll see that I'm using PowerShell Core from a mac. Everyone else on my team is using Windows, including the build pipelines mentioned. Each yielding the same results.

This has been used in our packer builds for some time now, and haven't ran into any issues until today (4/6).

From MS Documentation:

Find-PackageProvider -Name "Nuget" -AllVersions
Install-PackageProvider -Name "Nuget" -RequiredVersion "2.8.5.216" -Force

Results:

# Search for the package provider
Find-PackageProvider -Name "NuGet" -AllVersions -Verbose
VERBOSE: Using the provider 'Bootstrap' for searching packages.
VERBOSE: Finding the package 'Bootstrap::FindPackage' 'NuGet','','','''.
VERBOSE: Using the provider 'PowerShellGet' for searching packages.
VERBOSE: The -Repository parameter was not specified.  PowerShellGet will use all of the registered repositories.
VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.
VERBOSE: The specified Location is 'https://www.powershellgallery.com/api/v2' and PackageManagementProvider is 'NuGet'.
VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='NuGet'' for ''.
VERBOSE: Total package yield:'3' for the specified package 'NuGet'.
Find-PackageProvider: No match was found for the specified search criteria and package name 'NuGet'. Try Get-PackageSource to see all available registered package sources.
# Attempt installing package provider
Install-PackageProvider -Name NuGet -Verbose
VERBOSE: Using the provider 'Bootstrap' for searching packages.
VERBOSE: Finding the package 'Bootstrap::FindPackage' 'NuGet','','','''.
Install-PackageProvider: No match was found for the specified search criteria for the provider 'NuGet'. The package provider requires 'PackageManagement' and 'Provider' tags. Please check if the specified package has the tags.
# Attempt installing package provider specifying PSGallery source
Install-PackageProvider -Name "NuGet" -Source "PSGallery" -Verbose
VERBOSE: Repository details, Name = 'PSGallery', Location = 'https://www.powershellgallery.com/api/v2'; IsTrusted = 'False'; IsRegistered = 'True'.
Install-PackageProvider: No match was found for the specified search criteria for the provider 'NuGet'. The package provider requires 'PackageManagement' and 'Provider' tags. Please check if the specified package has the tags.
rouke-broersma commented 4 years ago

Have you tried explicitly setting tls 1.2? See: https://devblogs.microsoft.com/powershell/powershell-gallery-tls-support/

mil1i commented 4 years ago

Sorry I forgot to update this.

I was able to resolve with something similar to the above.

Little annoying that they only provided a temporary workaround in their post. At least someone in the comments lead us in the correct direction.

This is during a packer build for me. So my solution ended up being creating my first powershell provisioner to and starting a new powershell session:

# Set strong cryptography on 32 bit .Net Framework (version 4 and above)
Set-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\.NetFramework\\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord

# Set strong cryptography on 64 bit .Net Framework (version 4 and above)
Set-ItemProperty -Path 'HKLM:\\SOFTWARE\\Wow6432Node\\Microsoft\\.NetFramework\\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord

Temporary method was:

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Tls12'
rouke-broersma commented 4 years ago

Yea I agree...

MartinEtcheverry commented 3 years ago

i have the same problem with powershell on linux and "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Tls12'" didn't work , any idea ?