Search code examples
powershellnuget

Installing Module using Powershell


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
     

Solution

  • 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.