在尝试连接到Nuget时,我得到了下面的错误,然后我无法连接:
无法加载源的服务索引 https://api.nuget.org/v3/index.json。 发送请求时发生错误。 无法连接到远程服务器 连接尝试失败,原因是被连接方在一段时间后没有正确响应,或已建立连接 由于连接的主机未能响应68.232.34.200:443而失败
我可以在浏览器上访问https://api.nuget.org/v3/index.json。
在尝试连接到Nuget时,我得到了下面的错误,然后我无法连接:
无法加载源的服务索引 https://api.nuget.org/v3/index.json。 发送请求时发生错误。 无法连接到远程服务器 连接尝试失败,原因是被连接方在一段时间后没有正确响应,或已建立连接 由于连接的主机未能响应68.232.34.200:443而失败
我可以在浏览器上访问https://api.nuget.org/v3/index.json。
有些开发环境可能既不使用浏览器也不使用代理。
一种解决方案是从nugget(例如https://dotnet.myget.org/F/dotnet-core/api/v3/index.json)下载包到共享目录,然后执行以下操作:
dotnet add package Microsoft.AspNetCore.StaticFiles -s "shared drive:\index.json"
我希望这对你有用。
为了支持@Eddie Chen提供的答案(这里),我不得不将http_proxy设置添加到以下文件中:
C: \ Windows \ system32 \漫游配置systemprofile \ AppData \ \鸡块鸡块。配置
<add key="http_proxy" value="http://your_proxy_url:8080" />
我在Windows 10中使用docker-compose up命令在Dockerfile中运行RUN dotnet restore时遇到了同样的错误。
我已经尝试了互联网上提供的所有可能的解决方案,也一直在关注这个公开的问题。最后,在花了8个多小时后,通过遵循前面的步骤,我能够解决我的问题。
Uninstall Docker from your system Restart your system Install Docker from this link. Below is the version of my Docker Restart your system Start Docker for Windows, search Docker in the search bar in Windows. Make sure it is running. You should also go to Services.msc and make sure the services Docker Engine and Docker for Windows Service are running. At last, you must check your Nuget.config file from C:\Users\{Username}\AppData\Roaming\NuGet. For me, the content of that file was as below. <?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <add key="nuget.org" value="https://api.nuget.org/v3/index.json" /> </packageSources> <packageRestore> <add key="enabled" value="True" /> <add key="automatic" value="True" /> </packageRestore> <bindingRedirects> <add key="skip" value="False" /> </bindingRedirects> <packageManagement> <add key="format" value="0" /> <add key="disabled" value="False" /> </packageManagement> </configuration> Hope this helps.
当我试图浏览NuGet包时,我得到了同样的错误,以解决以下相同的步骤:
1-转到%appdata%\NuGet\NuGet.config
2-验证该配置中提到的url
3-删除不需要的url
4-重新启动visual studio并检查
当我试图通过Jenkins(配置为服务,默认使用本地系统帐户)运行nuget.exe时,我偶然发现了这个问题。我已经编辑了C:\Windows\System32\config\systemprofile\AppData\Roaming\NuGet\NuGet。配置文件,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="http_proxy" value="http://proxy_hostname_or_ip:3128" />
<add key="https_proxy" value="http://proxy_hostname_or_ip:3128" />
</config>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
为了测试命令提示符,可以通过PSTools启动:
psexec -i -s CMD
和实际测试运行在新创建的cmd窗口(运行为本地系统):
path_to_nuget\nuget.exe restore "path_to_solution\theSolution.sln"
我使用VSO/Azure DevOps。
您也可以直接在浏览器中访问提要url。你最终可能会得到这样的回复,这可能会让你的诊断更快:
用户没有使用ms.feed扩展名的许可证。
如果您得到此错误,但没有代理服务器,则可以转到
%userprofile%\AppData\Roaming\NuGet\NuGet.Config
并注释这行:
<config>
<!-- Proxy settings -->
<add key="http_proxy" value="host" />
<add key="http_proxy.user" value="username" />
<add key="http_proxy.password" value="encrypted_password" />
</config>
它为我工作,因为我得到了这个错误,但我没有代理服务器。
在我的情况下,我必须在Visual studio Options->NugetPAckageManager->sources中添加源 然后重新启动visual studio命令提示符
值得注意的是,.net核心SSL身份验证存在一个可能导致这种情况的错误。禁用他们最新的网络堆栈实现,为我解决了这个问题。
你可以永久地设置它,或者使用以下命令启动你的应用程序:
DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=0 dotnet ...
我有一个类似的问题,试图连接到我的私人TFS服务器,而不是公共NuGet API服务器。由于某种原因,我在AD服务器和TFS服务器之间出现了问题,因此它总是返回401。NuGet配置文章展示了你可以像这样将你的AD用户名和密码添加到配置文件中:
<packageSourceCredentials>
<vstsfeed>
<add key="Username" value="yourname@company.com" />
<add key="Password" value="this is an encrypted password" >
<!-- add key="ClearTextPassword" value="not recommended password" -->
</vstsfeed>
</packageSourceCredentials>
这不是一个非常理想的解决方案,更像是一个临时的解决方案,直到我可以找出AD服务器的问题,但这应该可以解决问题。
新包管理器的开发人员在2019年建议禁用tls 1.3作为解决方案(见第7705期)。
通过按Win + R打开注册表编辑器,并键入regedit Enter
导航到:
\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Client
将“DisabledByDefault key 0”的值修改为1
然后重新启动Visual Studio。
在维基百科上阅读更多关于TLS的信息 阅读更多关于问题7705 w.r.t. NuGet在github
第三方编辑
请注意,这将禁用操作系统的tls 1.3,而不仅仅是对nuget或dotnet。 Windows 10 1909版确实包含TLS 1.3的实验性实现,但后续版本应该没问题。基于无法浏览nuget包的一个答案,您可以通过控制台程序测试tls是否存在问题
static async Task Main(string[] args)
{
var client = new HttpClient();
string uri = "https://apiint.nugettest.org/v3-index/index.json";
var response = await client.GetAsync(uri);
string msg = "If you see this, your machine has no TLS/SSL issues with nuget.org";
Console.WriteLine(msg);
}
如果使用Visual Studio 2019,如果你在devenv.exe.config中没有使用任何默认代理,只需删除“defaultproxy”部分。在VS 2017中,这个部分没有出现
改变
<defaultProxy enabled="true" useDefaultCredentials="true">
<proxy bypassonlocal="True" proxyaddress="http://<yourproxy:port#>"/>
</defaultProxy>
to
<!--<defaultProxy enabled="true" useDefaultCredentials="true">
<proxy bypassonlocal="True" proxyaddress="http://<yourproxy:port#>"/>
</defaultProxy>-->
否则,提供适当的代理用户名和密码。
我试图添加一个Azure Artifacts NuGet源。
在这里,我遵循了微软的指示,但有一个关键的疏忽。
我忘记替换/v3/index了。Json和/v2。
安装小提琴也给我带来了类似的问题。卸载fiddler并从机器中删除fiddler代理。config(来自Framework和Framework64)解决了这个问题。
我在VS2010上使用的是旧版本的Nuget,默认为TLS 1.0 这里可以通过更改.Net框架使用的默认TLS版本来修复,该版本在注册表项中配置
reg add HKLM\SOFTWARE\Microsoft\.NETFramework\v4.0.30319 /v SystemDefaultTlsVersions /t REG_DWORD /d 1 /f /reg:64
reg add HKLM\SOFTWARE\Microsoft\.NETFramework\v4.0.30319 /v SystemDefaultTlsVersions /t REG_DWORD /d 1 /f /reg:32
FYI
6月15日,NuGet.org将永久移除对TLS 1.0和1.1的支持。请确保您的系统使用TLS 1.2。
您可以参考此链接了解TLS 1.2支持的信息
删除% AppData % \ \ NuGet \ NuGet徘徊。配置和重新启动VS2019对我来说很有效。
类似于https://github.com/NuGet/Home/issues/3281
如果您看到如下错误,您可能需要设置Azure Artifacts凭据,请参阅Github链接,您可以通过运行powershell脚本或手动安装凭据提供程序。
error : Response status code does not indicate success: 401 (Unauthorized).
I had the same error message while scaffolding Identity to my ASP.NET Core MVC project. Since my connection was not behind a proxy, removing/editing proxy configurations didn't make sense. And I didn't want to delete a file or uninstall PMC either. While looking around I realized a "Clear All Nuget Cache(s)" button on Tools --> Options --> NuGet Package Manager --> General. After pressing the button I had to wait for some time for the operation to complete. After that I tried to scaffold the Identity again but it didn't work. Then I decided to restart VS and voila :)
nuget restore
and
msbuild /t:restore
两者都没有为我工作,因为同样的错误。但
dotnet restore
完美的工作。试试
我无法解决问题本身,但找到了一种安装包的方法。
只要直接在包管理器控制台中指定nuget.org作为源。
Update-Package -reinstall -Source nuget.org
转到%appdata%\NuGet\NuGet.config 修改这一行: < packageSources > <add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft sdk \NuGetPackages\" /> . <add key="Package source" value="https://api.nuget.org/v3/index.json" /> . < / packageSources >
在我的例子中,问题在于我是在旧的Win7虚拟机上构建的。
我从https://github.com/NuGet/NuGetGallery/issues/8176#issuecomment-683923724找到了这个修复:
nuget.org started enforcing the use of TLS 1.2 (and dropped support for TLS 1.1 and 1.0) earlier this year. Windows 7 has TLS 1.2 disabled by default (check the DisabledByDefault value under HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client in your registry). To enable the support, please make sure you have an update (*) installed and switch the support on: reg add HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client" /v DisabledByDefault /t REG_DWORD /d 0 /f /reg:32 reg add "HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client" /v DisabledByDefault /t REG_DWORD /d 0 /f /reg:64 reg add "HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client" /v Enabled /t REG_DWORD /d 1 /f /reg:32 reg add "HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client" /v Enabled /t REG_DWORD /d 1 /f /reg:64
(*)更新指的是Microsoft kb3140245: Windows 7更新(KB3140245)
我安装了更新,重新启动(按照更新的要求),添加了那些注册表项,然后Nuget就可以正常工作了。
当我试图在本地托管的Gitlab实例中设置NuGet包时遇到了这个错误。错误提示401未经授权的代码。解决方案是用以下方法去除有害源:
nuget source Remove -Name SOURCE_NAME
然后添加相同的源,但这次在命令中指定用户名和密码:
nuget source Add -Name SOURCE_NAME -Source SOURCE_URL -UserName GITLAB_DEPLOY_TOKEN_USERNAME -Password GITLAB_DEPLOY_TOKEN
我在Visual Studio 2015上执行Install-Package Modernizr时遇到了类似的问题。我通过以下步骤解决了这个问题:
Download the package from its online source. Go to Tools/NuGet Package Manager/Package Manager Settings. Select Package Sources from the window. Add a new package source by clicking on the + sign. Enter a name and source location by clicking on ... (triple dot) sign. Make sure that only the package source that you've just added is checked. Uncheck all the other package sources. Go to Package Manager Console and type Install-Package Modernizr. Visual Studio 2015 installs the package automatically and creates Scripts and packages folders in your root folder.
我希望同样的解决方案在安装其他包时也能起作用。
在Windows 7上测试
步骤1:打开命令窗口(运行cmd) 步骤2:如果TLS 1.2被禁用(添加注册表项),执行以下命令启用TLS 1.2支持:
"HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client" /v DisabledByDefault /t REG_DWORD /d 0 /f /reg:32 reg add "HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client" /v DisabledByDefault /t REG_DWORD /d 0 /f /reg:64 reg add "HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client" /v Enabled /t REG_DWORD /d 1 /f /reg:32 reg add "HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client" /v Enabled /t REG_DWORD /d 1 /f /reg:64
我尝试了这里列出的许多答案,但这些都不能解决问题。最后,我不得不在Windows中的凭据管理器中删除“Windows凭据”下的VSCredentials_xxx条目,并重新启动Visual Studio 2019。
在那之后——在下一次VS启动时——VS终于向我要了代理凭证——在输入它们之后,Visual Studio就可以访问互联网了。
(似乎VS很久以前就存储了我最初提供的代理凭据-但因为在我们公司,他们在强制执行3个月后更改密码-凭据不再有效。)
你的一个金块来源可能无法到达。
在撰写本文时,AspNetCore (https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json)似乎有一个过期的证书或已被完全删除。
只需从设置中删除nuget源就可以解决这个问题
简单:
关闭VS2019 去c:\ users \you\ appdata \ roam \ nuget 删除文件NuGet。配置 重启VS2019
你可以开始了!
如果您是Windows用户,您可以在凭证管理器中删除或更新您的凭证。
Windows 10下,进入如下路径:
控制面板→所有控制面板项→证书管理器
或者在开始菜单的“搜索Windows”部分搜索“凭据管理器”。
然后在凭证管理器中,选择“Windows凭证”。
证书管理器将显示许多项,包括您的outlook和GitHub存储库下的“通用证书”
单击Git右侧的下拉箭头:它将显示编辑和删除选项。如果您删除,证书将在下次获取或拖动时弹出。或者你可以直接在那里编辑凭证。
我有一对Windows 2016服务器,其中Visual Studio无法连接到NuGet。在尝试了几乎所有其他建议的修复(注册表更改,Visual Studio/NuGet相关的缓存清理或文件/配置更改)后,以下是我们解决它的方法。
我们有一个组策略(GPO),设置了密码,我将这些密码添加到我们的GPO密码列表中,以使其工作。
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
https://github.com/NuGet/Announcements/issues/60
好吧,我尝试了上面所有的答案,希望我的注册表现在不是软管。但这似乎解决了我的问题:
https://learn.microsoft.com/en-us/answers/questions/959588/visual-studio-2022-won39t-connect-to-nuget.html
添加这个:TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
到this中逗号分隔的字符串:
微软HKLM \ SOFTWARE \政策\ \ SSL加密\ Configuration \ \ 00010002
我希望这能帮助下一个希望在周六早上快速进行有趣的概念验证,然后花3个小时寻找解决方案的人!!
我花了一天的时间,试遍了这里的一切。 对我来说,我没有在Visual Studio中更新我的密码!
I had changed my work Microsoft account password last week or so, I also use that account to login to visual studio, however I wasn't prompted to update it and was not logged out of Visual Studio, it remained logged in. When I clicked on my initials in the top right of visual studio > Account settings > under All Accounts the work account had yellow exclamation triangle warning sign next to it, updated the new password, then updated some packages, dotnet restore, cleaned & rebuilt and the errors are gone.
我必须在命令提示符中从.sln所在的文件夹中运行dotnet还原,这是成功的(而VS还原nuget包失败)。在此之后,我至少可以在Visual Studio下列出已安装的包,但“更新”仍然无法加载。
我删除了%localappdata%/Nuget中的所有内容,并清除了NuGets缓存。
dotnet nuget locals all --clear
重新启动后,Visual studio 2022恢复了我的包。
如果有人仍然有问题,NuGet答案不工作。下面的答案对我(一家DevOps Azure托管TFS的公司)来说是有效的:登录和退出团队基金会。TFS和VS都报告为已登录,但情况并非如此。不得不辞职——与op描述的症状相同。详情请参阅此答案。
这也可能由于身份验证问题而发生,因此您可能需要重新对Visual Studio进行身份验证。
在这种情况下,只需在包所在的文件夹中运行以下命令。配置文件的位置(通常是项目的根目录):
dotnet restore --interactive
系统将提示您从浏览器访问配对URL并输入配对代码,例如:
要登录,请使用网络浏览器打开页面https://microsoft.com/devicelogin,并输入代码C2DEJ87H到 身份验证。
这需要.NET CLI,它包含在.NET Core SDK中,可以从https://learn.microsoft.com/en-us/dotnet/core/install/windows安装