Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell Installing NuGet, says unable to access internet, but I actually can

I followed the steps mentioned in Using PowerShell Behind a Proxy to configure my proxy server.

netsh winhttp set proxy "[IP]:[Port]" $Wcl = New-Object System.Net.WebClient $Creds = Get-Credential $Wcl.Proxy.Credentials = $Creds 

A dialog popped up to collect my credential on the third line.

Then I tried to install NuGet:

PS C:\Users\Administrator> Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force WARNING: Unable to download from URI 'https://go.microsoft.com/fwlink/          ?LinkID=627338&clcid=0x409' to ''. WARNING: Unable to download the list of available providers. Check your internet          connection. 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. At line:1 char:1 + Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + CategoryInfo          : InvalidArgument: (Microsoft.Power...PackageProvider:InstallPackageProvider) [Install-PackageProvider], Exception     + FullyQualifiedErrorId : NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider 

The error message seems to indicate my PowerShell cannot connect to internet, but when I tried this command:

PS C:\Users\Administrator> Invoke-WebRequest "https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409"  StatusCode        : 200 StatusDescription : OK Content           : <?xml version="1.0" encoding="utf-8"?>                     <SoftwareIdentity xmlns="http://standards.iso.org/iso/19770/-2/2015/schema.xsd"                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:discovery="http://p... RawContent        : HTTP/1.1 200 OK                     Content-MD5: 01uMBNqAHedJsS1dqKC5oA==                     Vary: Accept-Encoding                     X-Cache: HIT                     x-ms-blob-type: BlockBlob                     x-ms-lease-status: unlocked                     x-ms-request-id: 1b7af5a7-901e-0003-5d94-f5cc950000... Forms             : {} Headers           : {[Content-MD5, 01uMBNqAHedJsS1dqKC5oA==], [Vary, Accept-Encoding], [X-Cache, HIT],                     [x-ms-blob-type, BlockBlob]...} Images            : {} InputFields       : {} Links             : {} ParsedHtml        : System.__ComObject RawContentLength  : 1847 

It seems it can connect to the Internet after all.

What did I do wrong? How do I install NuGet?

EDIT: I tried Ocaso Protal's suggestion:

PS C:\Users\Administrator> Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -proxy [ProxyServer:Port] -proxycredential $Creds WARNING: Unable to download from URI 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409' to ''. WARNING: Unable to download the list of available providers. Check your internet connection. 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. At line:1 char:1 + Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force  ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + CategoryInfo          : InvalidArgument: (Microsoft.Power...PackageProvider:InstallPackageProvider) [Install-Pac    kageProvider], Exception     + FullyQualifiedErrorId : NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackagePro    vider  PS C:\Users\Administrator> $Creds  UserName                                   Password --------                                   -------- [My UserName] System.Security.SecureString 

It seems to have no effect.

like image 991
KC Wong Avatar asked Apr 24 '19 09:04

KC Wong


People also ask

How do I install the NuGet provider for PowerShell?

Restart PowerShell to auto-load the package provider. Alternatively, run Get-PackageProvider -ListAvailable to list all the package providers available on the computer. Then use Import-PackageProvider -Name NuGet -RequiredVersion 2.8. 5.201 to import the provider to the current Windows PowerShell session.

Can not install NuGet?

Solution for unable to install NuGet provider for PowerShellRun both cmdlets to set . NET Framework strong cryptography registry keys. After that, restart PowerShell and check if the security protocol TLS 1.2 is added. As of last, install the PowerShellGet module.


1 Answers

could be TLS security related (ref: https://rnelson0.com/2018/05/17/powershell-in-a-post-tls1-1-world/)

Try this command first:

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

then try to do the update. Note: the command only affects the current session and does not persist.

You may also check what version of TLS for client is set on computer. Looks like TLS 1.0 for client is required. (ref: https://powershell.org/forums/topic/wmf-5-1-upgrade-broken-repositories/)

Michael

like image 134
Michael Cohoon Avatar answered Sep 23 '22 15:09

Michael Cohoon