混合专用 NuGet 源和 NEST 时"dotnet 还原"失败


dotnet restore

在某些软件包上意外失败,我不知道为什么。

我有一个通过 VSTS 包扩展托管的专用 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 Filesdotnetsdk1.0.0NuGet.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:Userstestdotnetdotnet.csproj]
C:Program Filesdotnetsdk1.0.0NuGet.targets(97,5): error : Response status code does not indicate success: 401 (Unauthorized). [C:Userstestdotnetdotnet.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 Filesdotnetsdk1.0.0NuGet.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:Usersdavidftempdotnetdotnet.csproj]
C:Program Filesdotnetsdk1.0.0NuGet.targets(97,5): error : Response status code does not indicate success: 401 (Unauthorized). [C:Usersdavidftempdotnetdotnet.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 Filesdotnetsdk1.0.0

完整的控制台输出

C:Usersdavidftempdotnet>dotnet restore -v diag
C:Program Filesdotnetsdk1.0.0MSBuild.dll /NoLogo /ConsoleLoggerParameters:Verbosity=Minimal /Logger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,C:Program Filesdotnetsdk1.0.0dotnet.dll /m /t:Restore /v:m /verbosity:diag .dotnet.csproj
Restoring packages for C:Usersdavidftempdotnetdotnet.csproj...
C:Program Filesdotnetsdk1.0.0NuGet.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:Usersdavidftempdotnetdotnet.csproj]
C:Program Filesdotnetsdk1.0.0NuGet.targets(97,5): error :   Response status code does not indicate success: 401 (Unauthorized). [C:Usersdavidftempdotnetdotnet.csproj]

更多信息 -

似乎当我只使用官方 nuget.org 源时,NEST 将像预期的任何其他 NuGet 包一样工作。如果包名称中有拼写错误,则会收到类似error : Unable to resolve NestOops

但是,当我将 NuGet 源作为其他包源时,包名称的任何拼写错误都会导致我的源中出现 401。我仍然不知道为什么 NEST 会有同样的错误。

看起来像是虚惊一场!

NuGet 配置不太正确 -<packageCredentials>应该是<packageSourceCredentials>

我的猜测是 VSTS 提要中的一些包被缓存了(一个单独的项目有自己的配置,其中包含正确的元素,首先将它们放入缓存中),这就是为什么它们似乎可以正确解析,即使它们没有正确进行身份验证。然后,每当查找不在缓存中的包时,它都会使用错误的凭据访问我们的提要并失败。

最新更新