我在Azure Artifacts中创建了一个提要,我想向其发布Nuget包。我已经生成了一个具有正确范围的个人访问令牌。
运行此命令成功:
> nuget.exe push -Source "myAzureFeed" -Apikey $(cat apikey) .binDebug/MyPackage1.2.3.nupkg
然而,此命令:
> dotnet nuget push .binDebugMyPackage.1.2.3.nupkg -s "myAzureFeed" -k $(cat apikey)
给我401
PS D:NuGetcreate-packageusing-dotnet-cli> dotnet nuget push .binDebugMyPackage.1.2.3.nupkg -s myAzureFeed -k $(cat apikey)
Pushing MyPackage.1.2.3.nupkg to 'https://pkgs.dev.azure.com/123/abc/_packaging/xyz/v2/'...
PUT https://pkgs.dev.azure.com/123/abc/_packaging/xyz/nuget/v2/
Unauthorized https://pkgs.dev.azure.com/123/abc/_packaging/xyz/v2/'...
PUT https://pkgs.dev.azure.com/123/abc/_packaging/xyz/nuget/v2/ 1323ms
error: Response status code does not indicate success: 401 (Unauthorized).
为什么nuget.exe push
成功,dotnet nuget push
失败?
为什么nuget.exe推送成功而dotnet nuget推送失败?
已经有GitHub的罚单在谈论这件事了。参见JeremyTCD的评论:
-api密钥适用于某些提要(例如Nuget.org(,但不适用于其他提要(例如Azure工件提要(。对于后一种饲料,你需要指定密码。不幸的是,网络不接受密码nuget或nuget CLI,所以你必须在nuget.config中设置它。最简单更新nuget.config的方法是nuget-sources-add。。。。
dotnet nuget push命令将包推送到服务器并发布。push命令使用系统的NuGet config file
或配置文件链中的服务器和凭据详细信息。有关详细信息,请参阅dotnet nuget推送。
因此,在使用dotnet nuget push
命令之前,您应该将凭证和API密钥添加到NuGet.config
中,如下所示:
nuget sources Add -Name "mysource" -Source "https://XXX.pkgs.visualstudio.com/_packaging/YYY/nuget/v3/index.json" -username name -password PAT nuget setapikey mykey -source mysource
然后通过dotnet NuGet push命令推送NuGet包:
dotnet nuget push packagename.nupkg --source mysource --api-key mykey
您还可以参考此处指示的示例:通过运行dotnet nuget
命令,从外部源发布包。