Azure Artifacts 在发布 nuget 包时出现 401 错误
Azure Artifacts gives 401 error on publishing a nuget package
将 Nuget 包推送到 Azure Artifacts 总是会出现 401 错误。请注意,API 密钥刚刚从 Azure 门户复制。可能是什么问题?
dotnet nuget push out/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/”...
错误:响应状态代码不表示成功: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>
1.Looks 就像您尝试将凭据添加到 Nuget.config
文件一样,不推荐 因为:
我们强烈建议不要将 PAT 签入源代码管理。任何有权访问您的 PAT 的人都可以访问您的 Azure DevOps 服务。
虽然不推荐,但应该可以。对我来说,我使用如下命令:
dotnet nuget push --source "myfeed" --api-key az Test.1.0.0.nupkg
和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>
这意味着您需要 create PAT 范围为您要访问的组织,并具有以下权限:打包(读取)、打包(读取和写入)或打包(读取、编写和管理)。
那么应该是<add key="ClearTextPassword" value="%PAT%" />
.
2.And 另一个方向是在 non-interactive scenarios.
中使用 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"}]}
将 Nuget 包推送到 Azure Artifacts 总是会出现 401 错误。请注意,API 密钥刚刚从 Azure 门户复制。可能是什么问题?
dotnet nuget push out/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/”...
错误:响应状态代码不表示成功: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>
1.Looks 就像您尝试将凭据添加到 Nuget.config
文件一样,不推荐 因为:
我们强烈建议不要将 PAT 签入源代码管理。任何有权访问您的 PAT 的人都可以访问您的 Azure DevOps 服务。
虽然不推荐,但应该可以。对我来说,我使用如下命令:
dotnet nuget push --source "myfeed" --api-key az Test.1.0.0.nupkg
和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>
这意味着您需要 create PAT 范围为您要访问的组织,并具有以下权限:打包(读取)、打包(读取和写入)或打包(读取、编写和管理)。
那么应该是<add key="ClearTextPassword" value="%PAT%" />
.
2.And 另一个方向是在 non-interactive scenarios.
中使用 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"}]}