在Visual Studio 2015 Update 2

时间:2016-05-06 20:24:29

标签: visual-studio-2015 nuget

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

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

Visual Studio信息:

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

错误代码:

  

'GET的HTTP请求   https://api.nuget.org/packages/hangfire.core.1.5.6.nupkg';有时间   在100000ms之后出来。

到目前为止我尝试过:

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

1 个答案:

答案 0 :(得分:0)

我没有C:\ Users \ CurrentUser.nuget文件,因此无法对此发表评论。在我的情况下,由于使用VS 2015 Update 2 dotnetcore项目构建的项目的“dotnet restore”问题,我最近一直在使用我的nuget.config文件。首先,nuget.config位于此处:C:\Users\<username>\AppData\Roaming\NuGet\NuGet.Config

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

出于本文的目的,我将使用命令行使用ConEmu进行“dotnet restore”。

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

$ 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).

所以我又回到了早期版本的NuGet.Config,如下所示:

<?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>

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

$ 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\

因此,有一个建议是通过命令行尝试“dotnet restore”,看看正在使用的NuGet Config文件以及正在使用的Feed。此外,您可以尝试将https://www.nuget.org/api/v2/作为包源添加到该NuGet.Config,看看是否能解决问题。

对于笑嘻嘻和笑声,我将“Hangfire.Core”添加到我的project.json中,其中我对此一无所知,看看它会如何反应:

"Hangfire.Core": "1.5.6"

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

$ 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\

奇怪的是v2对我来说很有用。当然,我的机器上有VS 2010,2012,2013和2015。以下是我在nuget主页上发现的内容:

  
    

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

  

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

我更改了project.json,看看dotnetcore是否支持“Hangfire.Core”当前的beta版本:

"Hangfire.Core": "1.6.0-beta3"

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

<?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>

然而,当我运行“dotnet restore”时,它失败了上面的NuGet.Config文件:

$ 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

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

<?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>

以下是命令行结果,虽然它的当前beta状态中的“Hangfire.Core”与dotnetcore不兼容。但是,嘿,至少饲料现在正在使用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\

所以我从几个不同的方向来到这里。也许它会对你所看到的问题有所帮助。

更新1:

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

$ 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

但是一段时间后它会成功运作。因此,我们所拥有的防火墙/代理问题会污染上面的整个钻井平台。