Unable to install NuGet package provider in PowerShell Core on Linux

Viewed 4432

I'm trying to set up the NuGet package provider on Linux in PowerShell 7 so I can use
Install-Package to get a package from the NuGet Gallery. However, when I run:

Install-PackageProvider -Name NuGet -Force

I get the following error:

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.

I did a bit of searching and found a few questions from this site and others where this error occurs, some answers saying I need to force TLS 1.2:

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12

some saying to specify -RequiredVersion on Install-PackageSource, some saying to use
-ForceBootstrap, and some saying to use -Force. None of these work and I'm still met with the same error each time. Get-PackageProvider lists NuGet as a provider.

I'm was also unable to install the NuGet provider on Windows using PowerShell Core with the same error. Is this just not supported from PowerShell Core?

4 Answers

I also received this error and specifying the version (currently 3.0.0.1) also fails. What worked for me was piping the packageprovider into Install-PackageProvider

Get-PackageProvider | where name -eq 'nuget' | Install-PackageProvider

You may add -Force if you want to avoid answering yes to The package(s) come(s) from a package source that is not marked as trusted. Are you sure you want to install software from ''?

The NuGet location has been updated. You can also do it in one line:

Register-PackageSource -Name nuget.org -ProviderName NuGet -Location "https://api.nuget.org/v3/index.json" -Trusted

Having TLS12 set in conjunction with Install Nuget package worked for me.

Below is how I used the command:

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
Install-PackageProvider -Name NuGet

In addition to @DougMaurer's answer, I also had to configure the package source as well:

$sourceArgs = @{
  Name = 'nuget.org'
  Location = 'https://api.nuget.org/v3/index.json'
  ProviderName = 'NuGet'
}
Register-PackageSource @sourceArgs
Related