我没有 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 配置文件以及正在使用哪些提要。此外,您可以尝试将 https://www.nuget.org/api/v2/ 作为包源添加到该 NuGet.Config 中,看看是否可以解决问题。
为了笑容和笑声,我在我的 project.json 中添加了“Hangfire.Core”,我对此一无所知,看看它会如何反应:
"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 提要 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 在其当前的 beta 版本中是否支持“Hangfire.Core”:
"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>
这里是命令行结果,尽管“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
但是它会在一段时间后成功运行。因此,我们遇到的这个防火墙/代理问题污染了上面的整个繁琐程序。