gpt4 book ai didi

c# - 使用 dotnet add package 忽略无法访问的源

转载 作者:行者123 更新时间:2023-12-03 19:18:13 30 4
gpt4 key购买 nike

当我尝试通过 dotnet 添加 NuGet 包时cli 我收到一个错误,提示它无法访问我的自定义 NuGet 源之一。有没有办法说“我不在乎, 从哪里可以恢复”?

McMaster.Extensions.CommandLineUtils显然它存在于 NuGet.org 中,它找到了它,但随后停止了 b/c,它无法访问自定义源🤷‍♂️。

PS c:\Temp\blah-project> dotnet add package McMaster.Extensions.CommandLineUtils
info : Adding PackageReference for package 'McMaster.Extensions.CommandLineUtils' into project 'c:\Temp\blah-project\blah-project.csproj'.
info : Restoring packages for c:\Temp\blah-project\blah-project.csproj
info : GET https://api.nuget.org/v3-flatcontainer/mcmaster.extensions.commandlineutils/index.json
info : OK https://api.nuget.org/v3-flatcontainer/mcmaster.extensions.commandlineutils/index.json 147ms
error: Unable to load the service index for source https://myinstace.pkgs.visualstudio.com/_packaging/Blah/nuget/v3/index.json.
error: Response status code does not indicate success: 401 (Unauthorized).

最佳答案

dotnet命令有 option指定 --source .这允许您仅从特定位置恢复包,在这种情况下您想要使用

dotnet restore --source https://api.nuget.org/v3/index.json`

这应该将包下拉到您本地的 NuGet 存储并解决您机器上的问题。

为了将包添加到您的项目中,您可能需要手动添加 <PackageReference>到你的项目
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="2.6.0" />

然后运行上面的恢复命令将为您获取包。

作为更永久的修复,您应该输入 nuget.config项目/存储库根目录中的文件,您可以在其中指定该特定项目的包源。您可以设置一些设置来覆盖系统的全局 nuget 配置/源。查看更多信息 nuget.config .您可以使用 dotnet new nugetconfig 在您的存储库中创建一个起始 nuget.config

关于c# - 使用 dotnet add package 忽略无法访问的源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60062106/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com