Azure Artifacts在发布nuget程序包时出现401错误 [英] Azure Artifacts gives 401 error on publishing a nuget package

查看:129
本文介绍了Azure Artifacts在发布nuget程序包时出现401错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将Nuget包推送到Azure Artifacts总是会出现401错误.请注意,API密钥只是从Azure门户复制的.可能是什么问题?

Pushing a Nuget package to Azure Artifacts always gives 401 error. Note that the API key was just copied from Azure portal. What could be the issue?

dotnet nuget推出/MonoTorrent.1.0.39.nupkg -s"myfeed" -k"myapikey"

dotnet nuget push out/MonoTorrent.1.0.39.nupkg -s "myfeed" -k "myapikey"

输出:

将MonoTorrent.1.0.39.nupkg推送到'

Pushing MonoTorrent.1.0.39.nupkg to 'https://pkgs.dev.azure.com/myacct/c7fc868d-fd14-4f27-a36a-8ff9add6482c/_packaging/c2fe5b0f-251b-4017-9848-ed4b906d9fc0/nuget/v2/'...

PUT https://pkgs.dev.azure.com/myacct/c7fc868d-fd14-4f27-a36a-8ff9add6482c/_packaging/c2fe5b0f-251b-4017-9848-ed4b906d9fc0/nuget/v2/

未经授权的 https://pkgs.dev.azure.com/myacct/c7fc868d-fd14-4f27-a36a-8ff9add6482c/_packaging/c2fe5b0f-251b-4017-9848-ed4b906d9fc0/nuget/v2/ 1248ms

Unauthorized https://pkgs.dev.azure.com/myacct/c7fc868d-fd14-4f27-a36a-8ff9add6482c/_packaging/c2fe5b0f-251b-4017-9848-ed4b906d9fc0/nuget/v2/ 1248ms

错误:响应状态代码未指示成功:401(未授权).

error: Response status code does not indicate success: 401 (Unauthorized).

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="myfeed" value="https://pkgs.dev.azure.com/myacct/myproject/_packaging/myfeed/nuget/v3/index.json" />
  </packageSources>
    <myfeed>
      <add key="Username" value="myliveidemail" />
      <add key="ClearTextPassword" value="myapikey" />
    </myfeed>
</configuration>

推荐答案

1.好像您正在尝试将凭据添加到 Nuget.config 文件中,因此不推荐,因为:

1.Looks like you're trying to add the credentials into Nuget.config file, this is not recommended because:

我们强烈建议您不要将PAT签入源代码管理中.有权访问您的PAT的任何人都可以访问您的Azure DevOps服务.

尽管不建议这样做,但它应该可以工作.对我来说,我使用以下命令:

Though it's not recommended, it should work. For me I use command like:

dotnet nuget push --source "myfeed" --api-key az Test.1.0.0.nupkg

和Nuget.config:

And the Nuget.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="myfeed" value="https://pkgs.dev.azure.com/myacct/myproject/_packaging/myfeed/nuget/v3/index.json" />
  </packageSources>
  <packageSourceCredentials>
    <myfeed>
      <add key="Username" value="lancel" />
      <add key="ClearTextPassword" value="YourPat, instead of the APIkey" />
    </myfeed>
  </packageSourceCredentials>
</configuration>

这意味着您需要

It means you'll need to create PAT which is scoped to the organization(s) you want to access with following permissions: Packaging (read), Packaging (read and write), or Packaging (read, write, and manage).

然后应为< add key ="ClearTextPassword"值=%PAT%"/> .

2.另一个方向是在

2.And another direction is to use Azure Artifacts Credential Provider in non-interactive scenarios.

运行帮助程序脚本以自动安装它,并设置一个 VSS_NUGET_EXTERNAL_FEED_ENDPOINTS 变量.该变量的值应为:

Run the helper script to install it automatically and set a VSS_NUGET_EXTERNAL_FEED_ENDPOINTS variable. The value of this variable should be:

{"endpointCredentials": [{"endpoint":"https://pkgs.dev.azure.com/myacct/myproject/_packaging/myfeed/nuget/v3/index.json", "password":"PAT"}]}

这篇关于Azure Artifacts在发布nuget程序包时出现401错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆