.net-core - 为什么由于不相关的包源没有响应而导致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 试图从不相关的包源加载服务索引?
解决方案
推荐阅读
- schema - ® 符号未在 JSON-LD 中解析。反斜杠(/)不起作用
- c# - 将带有 HttpContext.Session 的 UserID 传递给不同的控制器
- javascript - 从对象数组中获取所有值到数组中
- reactjs - 当 ViewPager 移动到下一张幻灯片时,上一张幻灯片应该减少每次移动的不透明度值
- pandas - pandas:从现有列值创建一个新数据框
- python - 将 sql server 连接到 Python3 - 客户端-服务器
- python-3.x - 当我的密码是我第一次下载 postgresql 时设置的密码时,为什么会收到 asyncpg.exceptions.InvalidPasswordError?
- python-3.x - python3中urllib.request中urlopen的奇怪行为
- c# - c# 中的简单批处理文件处理函数中可能存在内存泄漏
- python - 我们在 python 中需要 `sys` 模块有什么用途?