Azure Artifacts 在发布 nuget 包时出现 401 错误

fro*_*sty 8 azure-devops azure-artifacts

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

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

输出:

将 MonoTorrent.1.0.39.nupkg 推送到 ' 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/

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

错误:响应状态代码不表示成功:401(未经授权)。

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>
    <myfeed>
      <add key="Username" value="myliveidemail" />
      <add key="ClearTextPassword" value="myapikey" />
    </myfeed>
</configuration>
Run Code Online (Sandbox Code Playgroud)

Lan*_*SFT 4

1.看起来您正在尝试将凭据添加到Nuget.config文件中,不建议这样做,因为:

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

尽管不推荐,但它应该有效。对我来说,我使用如下命令:

dotnet nuget push --source "myfeed" --api-key az Test.1.0.0.nupkg
Run Code Online (Sandbox Code Playgroud)

和 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>
Run Code Online (Sandbox Code Playgroud)

这意味着您需要创建 PAT,其范围仅限于您想要使用以下权限访问的组织:打包(读取)、打包(读取和写入)或打包(读取、写入和管理)。

那么应该是<add key="ClearTextPassword" value="%PAT%" />

2.另一个方向是在非交互式场景中使用Azure Artifacts Credential Provider 。

运行帮助程序脚本以自动安装它并设置变量VSS_NUGET_EXTERNAL_FEED_ENDPOINTS。该变量的值应该是:

{"endpointCredentials": [{"endpoint":"https://pkgs.dev.azure.com/myacct/myproject/_packaging/myfeed/nuget/v3/index.json", "password":"PAT"}]}
Run Code Online (Sandbox Code Playgroud)