带有源的 dotnet 添加包给出未经授权的错误 401 和 404 未找到

dotnet add package with source giving an unauthorize error 401 and 404 Not found

我们正在更新 dotnet 应用程序中的 nuget 包,使用 dotnet 添加来自 Azure Devops 中私有源的包“包名称”。 最近我们更新到.net 5.0.1(我不确定它是否与这个问题有关。) 但是现在 运行 上面的命令在本地机器和 azure piplelines 中给出了错误。 我已经尝试了 --interactive 选项并刷新了包等的 PAT。

command dotnet add "csprojFile" package "mypackageName"

Determining projects to restore...
      Writing C:\Users\SirajUrRahman\AppData\Local\Temp\tmpD8BD.tmp
    info : Adding PackageReference for package 'my package' into project '.\my csproj'.
    info :   GET https://api.nuget.org/v3/registration5-gz-semver2/mypackageName/index.json
    info :   NotFound https://api.nuget.org/v3/registration5-gz-semver2/mypackageName/index.json 889ms
    error: Unable to load the service index for source https://pkgs.dev.azure.com/myorganization/_packaging/Feed/nuget/v3/index.json.
    error:   Response status code does not indicate success: 401 (Unauthorized).
    
    
Usage: NuGet.CommandLine.XPlat.dll package add [options]

Options:
  -h|--help               Show help information
  --force-english-output  Forces the application to run using an invariant, English-based culture.
  --package               Id of the package to be added.
  --version               Version of the package to be added.
  -d|--dg-file            Path to the dependency graph file to be used to restore preview and compatibility check.
  -p|--project            Path to the project file.
  -f|--framework          Frameworks for which the package reference should be added.
  -n|--no-restore         Do not perform restore preview and compatibility check. The added package reference will be unconditional.
  -s|--source             Specifies NuGet package sources to use during the restore.
  --package-directory     Directory to restore packages in.
  --interactive           Allow the command to block and require manual action for operations like authentication.
  --prerelease            Allows prerelease packages to be installed.

感谢您的帮助。 如有需要,欢迎随时提问。

此问题与 .net 5 相关,github 上已经为此创建了一个错误,这里是 link。 https://github.com/NuGet/Home/issues/10305.