【发布时间】:2017-03-29 15:35:49
【问题描述】:
dotnet restore 在某些包上对我来说意外失败,我不知道为什么。
我有一个通过 VSTS Packages 扩展托管的私有 NuGet 存储库,我的 NuGet.Config 看起来像(如此处所述 https://www.visualstudio.com/en-us/docs/package/nuget/auth#dotnet-core)
<?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="MyPackages" value="https://{myaccount}.pkgs.visualstudio.com/_packaging/{myfeed}/nuget/v3/index.json"` />
</packageSources>
<packageCredentials>
<MyPackages>
<add key="Username" value="vsts" />
<add key="ClearTextPassword" value="{my PAT}" />
</MyPackages>
</packageCredentials>
</configuration>
如果我使用 dotnet new console 创建一个新项目并添加对托管在我的提要上的包的引用,则恢复工作正常。
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="My.Lib" Version="1.0.0"></PackageReference>
</ItemGroup>
</Project>
但是,如果我还包含对 NEST 版本 2.5.0(或任何版本)的包引用,dotnet restore 会失败
C:\Program Files\dotnet\sdk\1.0.0\NuGet.targets(97,5): error : Unable to load the service index for source https://{myaccount}.pkgs.visualstudio.com/_packaging/{myfeed}/nuget/v3/index.json.\r `[C:\Users\test\dotnet\dotnet.csproj]
C:\Program Files\dotnet\sdk\1.0.0\NuGet.targets(97,5): error : Response status code does not indicate success: 401 (Unauthorized). [C:\Users\test\dotnet\dotnet.csproj]
但非常奇怪的是,将 NEST 替换为其他任何东西,恢复都可以。例如,添加 ElasticSearch.Net 2.5.0 即可。
如果我从我的 nuget.config 中删除我的包凭据和私有 NuGet 提要并仅引用 NEST,那么它可以工作 - 但我无法访问我的私有提要。
最后最奇怪的是,昨天恢复工作正常,但现在对我和我的同事来说,我们无法恢复。
这是 VSTS 包问题吗? NEST 有什么不同?
重现步骤
预期行为
dotnet restore 应该不会失败恢复
实际行为
dotnet restore fails - citing a 401 unauthorized response from the private nuget feed
C:\Program Files\dotnet\sdk\1.0.0\NuGet.targets(97,5): error : Unable to load the service index for source https://{account}.pkgs.visualstudio.com/_packaging/{feed}/nuget/v3/index.json.\r [C:\Users\davidf\temp\dotnet\dotnet.csproj]
C:\Program Files\dotnet\sdk\1.0.0\NuGet.targets(97,5): error : Response status code does not indicate success: 401 (Unauthorized). [C:\Users\davidf\temp\dotnet\dotnet.csproj]
环境数据
dotnet --info 输出:
dotnet --info
.NET Command Line Tools (1.0.0)
Product Information:
Version: 1.0.0
Commit SHA-1 hash: e53429feb4
Runtime Environment:
OS Name: Windows
OS Version: 10.0.14393
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\1.0.0
完整的控制台输出
C:\Users\davidf\temp\dotnet>dotnet restore -v diag
C:\Program Files\dotnet\sdk\1.0.0\MSBuild.dll /NoLogo /ConsoleLoggerParameters:Verbosity=Minimal /Logger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,C:\Program Files\dotnet\sdk\1.0.0\dotnet.dll /m /t:Restore /v:m /verbosity:diag .\dotnet.csproj
Restoring packages for C:\Users\davidf\temp\dotnet\dotnet.csproj...
C:\Program Files\dotnet\sdk\1.0.0\NuGet.targets(97,5): error : Unable to load the service index for source https://{account}.pkgs.visualstudio.com/_packaging/{feed}/nuget/v3/index.json.\r [C:\Users\davidf\temp\dotnet\dotnet.csproj]
C:\Program Files\dotnet\sdk\1.0.0\NuGet.targets(97,5): error : Response status code does not indicate success: 401 (Unauthorized). [C:\Users\davidf\temp\dotnet\dotnet.csproj]
更多信息 -
似乎当我只使用官方的 nuget.org 源时,NEST 将像预期的任何其他 NuGet 包一样工作。如果包名有错别字,你会得到类似error : Unable to resolve NestOops的错误
但是,当我将 NuGet 源作为附加包源时,包名称的任何拼写错误都会导致我的提要中出现 401。我仍然不知道为什么 NEST 会出现同样的错误。
【问题讨论】:
-
“dotnet restore failed”不是一个非常详细的诊断结果。 究竟会发生什么?您是否尝试过增加详细程度以显示
dotnet restore正在发出什么请求以及结果是什么?如果没有更多信息,任何人都很难为您提供帮助。 -
@JonSkeet 我在还原中添加了带有详细和诊断功能的 -v,但它并没有为我上面提到的输出添加太多内容。它只包含 msbuild 命令。输出导致恢复失败,从私有 nuget 存储库返回 401 未授权返回,这很奇怪,因为在不包含 NEST 之前请求是成功的
-
@JonSkeet 我用 -v diag 添加了控制台输出。 -v d 开关没有添加任何内容
-
https://www.visualstudio.com链接已损坏(“404 - 找不到页面”)。