在 Visual Studio 2015 Update 2 中获取依赖项时 NuGet 包管理器挂起 [英] NuGet package manager hangs when getting dependencies in Visual Studio 2015 Update 2

查看:30
本文介绍了在 Visual Studio 2015 Update 2 中获取依赖项时 NuGet 包管理器挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,我无法在我的解决方案中安装 NuGet 包,包管理器挂起.如果我删除包文件夹,则可以恢复当前的 NuGet 包,但无法添加新包.获取依赖项时包管理器挂起.

当前包源:https://api.nuget.org/v3/index.json

Visual Studio 信息:

Microsoft Visual Studio Professional 2015版本 14.0.25123.00 更新 2Microsoft .NET 框架版本 4.6.01055安装版本:专业版NuGet 包管理器 3.4.3

错误代码:

<块引用>

对GET"的 HTTP 请求https://api.nuget.org/packages/hangfire.core.1.5.6.nupkg';已计时100000 毫秒后退出.

到目前为止我尝试过的:

  • 关闭并重新打开 Visual Studio
  • 重新启动我的电脑
  • 从 Visual Studio 扩展和更新下载所有更新
  • 已删除项目文件夹和 C:\Users\CurrentUser\.nuget 下的包文件夹.然后可以在构建时恢复包,但我无法添加新包
  • Visual Studio 以管理员身份运行
  • 已删除解决方案 .suo 文件

解决方案

我没有 C:\Users\CurrentUser.nuget 文件,因此无法对此发表评论.就我而言,由于使用 VS 2015 Update 2 dotnetcore 项目构建的项目的dotnet restore"问题,我最近一直在玩我的 nuget.config 文件.首先,nuget.config 对我来说位于此处:C:\Users\\AppData\Roaming\NuGet\NuGet.Config

当我更改此文件时,它会影响我的 VS 2015 构建(即恢复)

出于本文的目的,我将使用命令行使用 ConEmu 执行dotnet restore".

我在需要代理身份验证的 nuget.config 中遇到了几个包源的问题.这是从命令行运行的示例:

$ dotnet restore日志:正在恢复 C:\<projectPath>\project.json 的包...信息:获取 https://api.nuget.org/v3-flatcontainer/microsoft.netcore.dotnethostresolver/index.json信息:好的 https://api.nuget.org/v3-flatcontainer/microsoft.netcore.dotnethostresolver/index.json 250ms错误:无法加载源 https://dotnet.myget.org/F/dotnet-cli/api/v3/index.json 的服务索引.错误:响应状态代码未指示成功:407(需要代理身份验证).

所以我恢复到 NuGet.Config 的早期版本,如下所示:

现在,当我从命令行运行dotnet restore"时,我看到:

$ dotnet restore日志:正在恢复 C:\<projectPath>\project.json 的包...信息:获取 https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.NETCore.DotNetHostResolver'信息:好的 https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.NETCore.DotNetHostResolver' 807ms信息:获取 https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.NETCore.DotNetHost'信息:好的 https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.NETCore.DotNetHost' 136ms日志:在 C:\<projectPath>\project.json 中恢复工具Microsoft.AspNetCore.Server.IISIntegration.Tools"的包...信息:提交还原...log :将锁定文件写入磁盘.路径:C:\\project.lock.json日志:C:\\project.json日志:在 9030 毫秒内完成恢复.使用的 NuGet 配置文件:C:\Users\\AppData\Roaming\NuGet\NuGet.ConfigC:\ProgramData\nuget\Config\Microsoft.VisualStudio.Offline.config使用的饲料:https://www.nuget.org/api/v2/C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

因此,一个建议是通过命令行尝试dotnet restore",看看正在使用哪些 NuGet 配置文件以及正在使用哪些提要.此外,您可以尝试添加 https://www.nuget.org/api/v2/ 作为NuGet.Config 的包源,看看是否能解决问题.

对于笑声和傻笑,我在我的 project.json 中添加了Hangfire.Core",我对此一无所知,以查看它的反应:

"Hangfire.Core": "1.5.6"

看起来像 v2 包源找到了它,但不幸的是我的项目与它不兼容所以...

$ dotnet restore日志:正在恢复 C:\<projectPath>\project.json 的包...信息:缓存 https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.NETCore.DotNetHostResolver'信息:缓存 https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.NETCore.DotNetHost'日志:在 C:\<projectPath>\project.json 中恢复工具Microsoft.AspNetCore.Server.IISIntegration.Tools"的包...错误:包 Hangfire.Core 1.5.6 与 netcoreapp1.0 (.NETCoreApp,Version=v1.0) 不兼容.包 Hangfire.Core 1.5.6 支持:net45 (.NETFramework,Version=v4.5)错误:包 Owin 1.0.0 与 netcoreapp1.0 (.NETCoreApp,Version=v1.0) 不兼容.包 Owin 1.0.0 支持:net40 (.NETFramework,Version=v4.0)错误:一个或多个包与 .NETCoreApp,Version=v1.0 不兼容.信息:提交还原...日志:锁定文件没有改变.跳过锁定文件写入.路径:C:\\project.lock.json日志:C:\\project.json日志:恢复在 1219 毫秒内失败.C:\\project.json 中的错误包 Hangfire.Core 1.5.6 与 netcoreapp1.0 (.NETCoreApp,Version=v1.0) 不兼容.包 Hangfire.Core 1.5.6 支持:net45 (.NETFramework,Version=v4.5)包 Owin 1.0.0 与 netcoreapp1.0 (.NETCoreApp,Version=v1.0) 不兼容.包 Owin 1.0.0 支持:net40 (.NETFramework,Version=v4.0)一个或多个包与 .NETCoreApp,Version=v1.0 不兼容.使用的 NuGet 配置文件:C:\Users\\AppData\Roaming\NuGet\NuGet.ConfigC:\ProgramData\nuget\Config\Microsoft.VisualStudio.Offline.config使用的饲料:https://www.nuget.org/api/v2/C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

奇怪的是 v2 完全适合我.当然,我的机器上有 VS 2010、2012、2013 和 2015.这是我从 nuget 主页上找到的内容:

<块引用><块引用>

•NuGet 提要 v3 (VS 2015/NuGet v3.x):https://api.nuget.org/v3/index.json
•NuGet 提要 v2(VS 2013 和较早的/NuGet 2.x):https://www.nuget.org/api/v2

所以再次进入违规行为......(即让 v3 为我在 VS 2015 中的dotnet restore"工作)

我更改了 project.json 以查看 dotnetcore 在其当前测试版中是否支持Hangfire.Core":

"Hangfire.Core": "1.6.0-beta3"

我还如下修改了我的 NuGet.Config 以包含 v3 版本:

但是,当我运行dotnet restore"时,上面的 NuGet.Config 文件失败了:

$ dotnet restore日志:正在恢复 C:\<projectPath>\project.json 的包...错误:无法加载源 https://api.nuget.org/v3/的服务索引.错误:发送请求时发生错误.错误:无法建立与服务器的连接

最终删除 activePackageSources 部分为我修复了错误,并允许我最终选择 v3 作为有效的包源.这是有效的新 NuGet.Config:

这里是命令行结果,尽管Hangfire.Core"在当前测试版中再次与 dotnetcore 不兼容.但是,嘿,至少提要现在使用的是 v3:

$ dotnet restore日志:正在恢复 C:\<projectPath>\project.json 的包...信息:获取 https://api.nuget.org/v3-flatcontainer/microsoft.netcore.dotnethostresolver/index.json信息:获取 https://api.nuget.org/v3-flatcontainer/hangfire.core/index.json信息:好的 https://api.nuget.org/v3-flatcontainer/microsoft.netcore.dotnethostresolver/index.json 168ms信息:获取 https://api.nuget.org/v3-flatcontainer/microsoft.netcore.dotnethost/index.json信息:好的 https://api.nuget.org/v3-flatcontainer/microsoft.netcore.dotnethost/index.json 182ms信息:好的 https://api.nuget.org/v3-flatcontainer/hangfire.core/index.json 578ms信息:获取 https://api.nuget.org/v3-flatcontainer/hangfire.core/1.6.0-beta3/hangfire.core.1.6.0-beta3.nupkg信息:好的 https://api.nuget.org/v3-flatcontainer/hangfire.core/1.6.0-beta3/hangfire.core.1.6.0-beta3.nupkg 215ms日志:安装 Hangfire.Core 1.6.0-beta3.日志:在 C:\<projectPath>\project.json 中恢复工具Microsoft.AspNetCore.Server.IISIntegration.Tools"的包...错误:包 Hangfire.Core 1.6.0-beta3 与 netcoreapp1.0 (.NETCoreApp,Version=v1.0) 不兼容.包 Hangfire.Core 1.6.0-beta3 支持:net45 (.NETFramework,Version=v4.5)错误:包 Owin 1.0.0 与 netcoreapp1.0 (.NETCoreApp,Version=v1.0) 不兼容.包 Owin 1.0.0 支持:net40 (.NETFramework,Version=v4.0)错误:一个或多个包与 .NETCoreApp,Version=v1.0 不兼容.信息:提交还原...log :将锁定文件写入磁盘.路径:C:\\project.lock.json日志:C:\\project.json日志:恢复在 5477 毫秒内失败.C:\\project.json 中的错误包 Hangfire.Core 1.6.0-beta3 与 netcoreapp1.0 (.NETCoreApp,Version=v1.0) 不兼容.包 Hangfire.Core 1.6.0-beta3 支持:net45 (.NETFramework,Version=v4.5)包 Owin 1.0.0 与 netcoreapp1.0 (.NETCoreApp,Version=v1.0) 不兼容.包 Owin 1.0.0 支持:net40 (.NETFramework,Version=v4.0)一个或多个包与 .NETCoreApp,Version=v1.0 不兼容.使用的 NuGet 配置文件:C:\Users\\AppData\Roaming\NuGet\NuGet.ConfigC:\ProgramData\nuget\Config\Microsoft.VisualStudio.Offline.config使用的饲料:https://api.nuget.org/v3/index.jsonC:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

所以我从几个不同的方向来到这里.也许它会帮助解决您所看到的问题.

更新 1:

所以我在通过dotnet restore"连接到 nuget v2 和 v3 包源时仍然遇到问题.大多数时候它不起作用,有时它起作用.我在想,也许我的公司有多个代理服务器可以将我们的请求过滤出去.我认为我们向世界发出的请求会通过其中一台服务器.有时我们会在一台服务器上运行一段时间,而突然我们在另一台服务器上.我的猜测是这些服务器中的一个让我们通过,而另一个不允许.我通过简单地从命令行一遍又一遍地运行dotnet restore"来测试它.大多数情况下它失败了:

$ dotnet restore日志:正在恢复 C:\<projectPath>\project.json 的包...错误:无法加载源 https://api.nuget.org/v3/index.json 的服务索引.错误:发送请求时发生错误.错误:无法建立与服务器的连接

但是它会在一段时间后成功运行.因此,我们遇到的这个防火墙/代理问题污染了上面的整个繁琐.

For some reason I can't install NuGet packages in my solution, package manager just hangs. If I delete the packages folder current NuGet packages can however be restored but new ones can't be added. Package manager hangs when getting dependencies.

Current package source: https://api.nuget.org/v3/index.json

Visual Studio information:

Microsoft Visual Studio Professional 2015 
Version 14.0.25123.00 Update 2 
Microsoft .NET Framework Version 4.6.01055 
Installed Version: Professional 
NuGet Package Manager 3.4.3

Error code:

The HTTP request to 'GET https://api.nuget.org/packages/hangfire.core.1.5.6.nupkg'; has timed out after 100000ms.

What I have tried so far:

  • Closed and reopened Visual Studio
  • Restarted my computer
  • Downloaded all updates from Visual Studio Extensions and Updates
  • Deleted packages folder both in projects folder and under C:\Users\CurrentUser\.nuget. Packages can then be restored upon build but I can't add a new package
  • Visual Studio is being run as administrator
  • Deleted the solutions .suo file

解决方案

I don't have a C:\Users\CurrentUser.nuget file so can't comment on that. In my case I've been playing around with my nuget.config file recently due to "dotnet restore" issues with a project built with VS 2015 Update 2 dotnetcore project. To start, nuget.config is located here for me: C:\Users\<username>\AppData\Roaming\NuGet\NuGet.Config

When I change this file it affects my VS 2015 builds (i.e. restore)

For the purposes of this post I will be using the command line to do "dotnet restore"s using ConEmu.

I was having issues with a couple of the package sources in nuget.config requiring proxy authentication. Here is a sample ran from the command line:

$ dotnet restore
log  : Restoring packages for C:\<projectPath>\project.json...
info :   GET https://api.nuget.org/v3-flatcontainer/microsoft.netcore.dotnethostresolver/index.json
info :   OK https://api.nuget.org/v3-flatcontainer/microsoft.netcore.dotnethostresolver/index.json 250ms
error: Unable to load the service index for source https://dotnet.myget.org/F/dotnet-cli/api/v3/index.json.
error:   Response status code does not indicate success: 407 (Proxy Authentication Required).

So I reverted back to an earlier version of NuGet.Config which is as follows:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <activePackageSource>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </activePackageSource>
  <packageSources>
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
  </packageSources>
</configuration>

Now when I run "dotnet restore" from the command line I see this:

$ dotnet restore
log  : Restoring packages for C:\<projectPath>\project.json...
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.NETCore.DotNetHostResolver'
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.NETCore.DotNetHostResolver' 807ms
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.NETCore.DotNetHost'
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.NETCore.DotNetHost' 136ms
log  : Restoring packages for tool 'Microsoft.AspNetCore.Server.IISIntegration.Tools' in C:\<projectPath>\project.json...
info : Committing restore...
log  : Writing lock file to disk. Path: C:\<projectPath>\project.lock.json
log  : C:\<projectPath>\project.json
log  : Restore completed in 9030ms.

NuGet Config files used:
    C:\Users\<user>\AppData\Roaming\NuGet\NuGet.Config
    C:\ProgramData\nuget\Config\Microsoft.VisualStudio.Offline.config

Feeds used:
    https://www.nuget.org/api/v2/
    C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

So one suggestion is to try "dotnet restore" via the command line and see what NuGet Config files are being used and which feeds are being used. Additionally you might try adding https://www.nuget.org/api/v2/ as a package source to that NuGet.Config and see if that resolves the issue.

For grins and giggles I added "Hangfire.Core", of which I know nothing about, to my project.json to see how it would react:

"Hangfire.Core": "1.5.6"

It looks like the v2 package source found it but unfortunately my project is not compatible with it so...

$ dotnet restore
log  : Restoring packages for C:\<projectPath>\project.json...
info :   CACHE https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.NETCore.DotNetHostResolver'
info :   CACHE https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.NETCore.DotNetHost'
log  : Restoring packages for tool 'Microsoft.AspNetCore.Server.IISIntegration.Tools' in C:\<projectPath>\project.json...
error: Package Hangfire.Core 1.5.6 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package Hangfire.Core 1.5.6 supports: net45 (.NETFramework,Version=v4.5)
error: Package Owin 1.0.0 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package Owin 1.0.0 supports: net40 (.NETFramework,Version=v4.0)
error: One or more packages are incompatible with .NETCoreApp,Version=v1.0.
info : Committing restore...
log  : Lock file has not changed. Skipping lock file write. Path: C:\<projectPath>\project.lock.json
log  : C:\<projectPath>\project.json
log  : Restore failed in 1219ms.

Errors in C:\<projectPath>\project.json
    Package Hangfire.Core 1.5.6 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package Hangfire.Core 1.5.6 supports: net45 (.NETFramework,Version=v4.5)
    Package Owin 1.0.0 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package Owin 1.0.0 supports: net40 (.NETFramework,Version=v4.0)
    One or more packages are incompatible with .NETCoreApp,Version=v1.0.

NuGet Config files used:
    C:\Users\<user>\AppData\Roaming\NuGet\NuGet.Config
    C:\ProgramData\nuget\Config\Microsoft.VisualStudio.Offline.config

Feeds used:
    https://www.nuget.org/api/v2/
    C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

What's weird is that v2 works at all for me. Granted I have VS 2010, 2012, 2013, and 2015 on my machine. Here is what I found from the nuget homepage:

•NuGet feed v3 (VS 2015 / NuGet v3.x): https://api.nuget.org/v3/index.json
•NuGet feed v2 (VS 2013 and earlier / NuGet 2.x): https://www.nuget.org/api/v2

So once more into the breach..... (i.e. get v3 to work for my "dotnet restore"s in VS 2015)

I changed the project.json to see if "Hangfire.Core" is supported by dotnetcore in it's current beta release:

"Hangfire.Core": "1.6.0-beta3"

I also modified my NuGet.Config as follows to include the v3 version:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <activePackageSource>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </activePackageSource>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
  </packageSources>
</configuration>

However when I run "dotnet restore" it fails with the above NuGet.Config file:

$ dotnet restore
log  : Restoring packages for C:\<projectPath>\project.json...
error: Unable to load the service index for source https://api.nuget.org/v3/.
error:   An error occurred while sending the request.
error:   A connection with the server could not be established

Ultimately removing the activePackageSources section fixed the error for me and allowed me to pick up v3 finally as a valid package source. Here is the new NuGet.Config that works:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
  </packageSources>
</configuration>

And here are the command line results, although again "Hangfire.Core" in it's current beta state is not compatible with dotnetcore. But hey, at least the feed is now using v3:

$ dotnet restore
log  : Restoring packages for C:\<projectPath>\project.json...
info :   GET https://api.nuget.org/v3-flatcontainer/microsoft.netcore.dotnethostresolver/index.json
info :   GET https://api.nuget.org/v3-flatcontainer/hangfire.core/index.json
info :   OK https://api.nuget.org/v3-flatcontainer/microsoft.netcore.dotnethostresolver/index.json 168ms
info :   GET https://api.nuget.org/v3-flatcontainer/microsoft.netcore.dotnethost/index.json
info :   OK https://api.nuget.org/v3-flatcontainer/microsoft.netcore.dotnethost/index.json 182ms
info :   OK https://api.nuget.org/v3-flatcontainer/hangfire.core/index.json 578ms
info :   GET https://api.nuget.org/v3-flatcontainer/hangfire.core/1.6.0-beta3/hangfire.core.1.6.0-beta3.nupkg
info :   OK https://api.nuget.org/v3-flatcontainer/hangfire.core/1.6.0-beta3/hangfire.core.1.6.0-beta3.nupkg 215ms
log  : Installing Hangfire.Core 1.6.0-beta3.
log  : Restoring packages for tool 'Microsoft.AspNetCore.Server.IISIntegration.Tools' in C:\<projectPath>\project.json...
error: Package Hangfire.Core 1.6.0-beta3 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package Hangfire.Core 1.6.0-beta3 supports: net45 (.NETFramework,Version=v4.5)
error: Package Owin 1.0.0 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package Owin 1.0.0 supports: net40 (.NETFramework,Version=v4.0)
error: One or more packages are incompatible with .NETCoreApp,Version=v1.0.
info : Committing restore...
log  : Writing lock file to disk. Path: C:\<projectPath>\project.lock.json
log  : C:\<projectPath>\project.json
log  : Restore failed in 5477ms.

Errors in C:\<projectPath>\project.json
    Package Hangfire.Core 1.6.0-beta3 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package Hangfire.Core 1.6.0-beta3 supports: net45 (.NETFramework,Version=v4.5)
    Package Owin 1.0.0 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package Owin 1.0.0 supports: net40 (.NETFramework,Version=v4.0)
    One or more packages are incompatible with .NETCoreApp,Version=v1.0.

NuGet Config files used:
    C:\Users\<user>\AppData\Roaming\NuGet\NuGet.Config
    C:\ProgramData\nuget\Config\Microsoft.VisualStudio.Offline.config

Feeds used:
    https://api.nuget.org/v3/index.json
    C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

So I came at this from a couple different directions. Perhaps it will help with the issue you're seeing.

Update 1:

So I continued to have issues connecting to the nuget v2 and v3 package sources via "dotnet restore". Most of the time it doesn’t work, sometimes it works. I’m thinking that perhaps my company has multiple proxy servers out there filtering our requests out to the world. I’m thinking our requests out to the world go through one of these servers. Sometimes we’re going through one server for a while when suddenly we are on another server. My guess is that one of these servers lets us through while another doesn’t allow it. I tested it by simply running "dotnet restore" from the command line over and over again. Mostly it failed with this:

$ dotnet restore
log  : Restoring packages for C:\<projectPath>\project.json...
error: Unable to load the service index for source https://api.nuget.org/v3/index.json.
error:   An error occurred while sending the request.
error:   A connection with the server could not be established

However it would successfully work after a while. So that whole rigmarole above is polluted by this firewall/proxy issue we're having.

这篇关于在 Visual Studio 2015 Update 2 中获取依赖项时 NuGet 包管理器挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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