PowerShell安装NuGet,说无法上网,但我其实可以 [英] PowerShell Installing NuGet, says unable to access internet, but I actually can

查看:30
本文介绍了PowerShell安装NuGet,说无法上网,但我其实可以的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照在代理后使用PowerShell中提到的步骤进行配置我的代理服务器.

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.

然后我尝试安装 NuGet:

Then I tried to install NuGet:

PS C:UsersAdministrator> 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

错误消息似乎表明我的 PowerShell 无法连接到互联网,但是当我尝试此命令时:

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

PS C:UsersAdministrator> 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

看来还是可以上网的.

我做错了什么?如何安装 NuGet?

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

我尝试了 Ocaso Protal 的建议:

I tried Ocaso Protal's suggestion:

PS C:UsersAdministrator> 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:UsersAdministrator> $Creds

UserName                                   Password
--------                                   --------
[My UserName] System.Security.SecureString

好像没有效果.

推荐答案

可能与 TLS 安全相关(参考:https://rnelson0.com/2018/05/17/powershell-in-a-post-tls1-1-world/)

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

先试试这个命令:

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

然后尝试进行更新.注意:该命令只影响当前会话,不会持续存在.

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

您还可以检查计算机上设置的客户端 TLS 版本.看起来需要客户端的 TLS 1.0.(参考:https://powershell.org/forums/topic/wmf-5-1-upgrade-broken-repositories/)

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/)

迈克尔

这篇关于PowerShell安装NuGet,说无法上网,但我其实可以的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆