首页 > 解决方案 > 为什么由于不相关的包源没有响应而导致nuget包安装失败

问题描述

我正在使用 dotnet cli 创建 f# 项目。我运行以下命令来安装 NewtonSoft.Json NuGet 包。

$>dotnet add src/Library/Library.fsproj package Newtonsoft.Json

输出是

  Writing C:\Users\MyUserName\AppData\Local\Temp\tmp440E.tmp
info : Adding PackageReference for package 'Newtonsoft.Json' into project 'src/Library/Library.fsproj'.
info : Restoring packages for c:\Learning\Projects\FSNetCore\FSNetCore\src\Library\Library.fsproj...
info :   GET https://api.nuget.org/v3-flatcontainer/newtonsoft.json/index.json
info :   OK https://api.nuget.org/v3-flatcontainer/newtonsoft.json/index.json 288ms
error: Unable to load the service index for source https://MyEmployer.pkgs.visualstudio.com/_packaging/NuGetServerName/nuget/v3/index.json.
error:   Response status code does not indicate success: 401 (Unauthorized).

我想知道为什么由于来自无关包源的 401 响应而导致此操作失败,该包源是用户级范围的Nuget.Config 文件指向的私有 azure 工件。

$>dotnet nuget --version
NuGet Command Line
5.2.0.3

通过明确指定 Source 和 version 可以成功地将包安装到项目中

$> dotnet add src/Library/Library.fsproj package Newtonsoft.Json --source https://api.nuget.org/v3-flatcontainer/newtonsoft.json/index.json --version 12.0.2
  Writing C:\Users\MyUserName\AppData\Local\Temp\tmp8A3B.tmp
info : Adding PackageReference for package 'Newtonsoft.Json' into project 'src/Library/Library.fsproj'.
info : Restoring packages for c:\Learning\Projects\FSNetCore\FSNetCore\src\Library\Library.fsproj...
info : Package 'Newtonsoft.Json' is compatible with all the specified frameworks in project 'src/Library/Library.fsproj'.
info : PackageReference for package 'Newtonsoft.Json' version '12.0.2' added to file 'c:\Learning\Projects\FSNetCore\FSNetCore\src\Library\Library.fsproj'.
info : Committing restore...
info : Writing assets file to disk. Path: c:\Learning\Projects\FSNetCore\FSNetCore\src\Library\obj\project.assets.json
log  : Restore completed in 193.98 ms for c:\Learning\Projects\FSNetCore\FSNetCore\src\Library\Library.fsproj.

为什么 dotnet cli 试图从不相关的包源加载服务索引?

标签: .net-corenuget-packagenuget-serverazure-artifacts

解决方案


推荐阅读