0

I am trying to install the NuGet module using Powershell. Though I am running the PowerShell with admin access, I got this error:

    NuGet provider is required to continue
    PowerShellGet requires NuGet provider version '2.8.5.201' or newer to 
    interact with NuGet-based repositories. The NuGet provider must be 
    available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
    'C:\Users\Admin\AppData\Local\PackageManagement\ProviderAssemblies'. You 
    can also install the NuGet provider by running 'Install-PackageProvider 
    -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet 
    to install and import the NuGet provider now?
    [Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y
    WARNING: Unable to download the list of available providers. Check your 
    internet connection.
    PackageManagement\Install-PackageProvider : Unable to resolve package 
    reference 'https://onegetcdn.azureedge.net/providers/nuget- 
    2.8.5.208.package.swidtag'.
    At C:\Program 
    Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7468 
    char:21
    + ...     $null = PackageManagement\Install-PackageProvider -Name 
    $script:N ...
    +                 
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: 
    (https://onegetc...package.swidtag:String) [Install-PackageProvider], 
    Exception
    + 

FullyQualifiedErrorId:UnableToResolvePackage,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider

    PackageManagement\Import-PackageProvider: No match was found for the 
    specified search criteria and provider name 'NuGet'. Try 'Get- 
    PackageProvider -ListAvailable' to see if the provider exists on the 
    system.
    At C:\Program 
    Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7474 
    char:21
    + ...     $null = PackageManagement\Import-PackageProvider -Name 
    $script:Nu ...
    +                 
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (NuGet:String) [Import- 
    PackageProvider], Exception
    + FullyQualifiedErrorId : 

NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider
     
gkubed
  • 1,849
  • 3
  • 32
  • 45
Pavithra
  • 59
  • 1
  • 12

1 Answers1

4

Try installing it like this if you're behind a corporate proxy - the first two additional lines will use your current credentials for subsequent cmdlets:

[System.Net.WebRequest]::DefaultWebProxy = [System.Net.WebRequest]::GetSystemWebProxy()
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
Install-PackageProvider -Name NuGet -MinimumVersion '2.8.5.201' -Force -Scope AllUsers

Or... you can use the -Proxy and -ProxyCredential switches for the Install-PackageProvider cmdlet.

Scepticalist
  • 3,737
  • 1
  • 13
  • 30
  • thank you for your efforts to help me...but I got an error while executing the last command The error is Install-PackageProvider: A positional parameter cannot be found that accepts argument '--MinimumVersion'. – Pavithra Jan 06 '20 at 10:31
  • 1
    What error? The same one? Did you try providing the -Proxy and -ProxyCredential switches instead? Are you behind a corporate proxy? Did you paste all 3 commands into ISE then run them or try running them one at a time? – Scepticalist Jan 06 '20 at 10:33
  • 1
    Put the version string in quotes and try again - I've edited my answer above as there was a typo also, -MinimumVersion should have one '-' not two '--'. – Scepticalist Jan 06 '20 at 10:36
  • For folks finding this answer nowadays, another piece of the puzzle I needed to resolve that error was setting the TLS version for subsequent commands. https://stackoverflow.com/a/61078227/3269584 – Bennett Elder Apr 07 '23 at 18:22