Push a NuGet package to VSTS with .NET CLI

为君一笑 提交于 2020-06-25 01:26:07

问题


I'm trying to publish a NuGet package to a private VSTS feed. I'd like to achieve that using only .NET CLI and without creating or modifying a nuget.config file.

I've tried to do:

dotnet nuget push <PackageName> --source https://XXX.pkgs.visualstudio.com/_packaging/YYY/nuget/v3/index.json --api-key <VSTS UserName>:<PersonalAccessToken>

I get: error: Unable to load the service index for source https://XXX.pkgs.visualstudio.com/_packaging/YYY/nuget/v3/index.json. error: Response status code does not indicate success: 401 (Unauthorized).

I can see in Fiddler that .NET CLI sends only a GET request to https://XXX.pkgs.visualstudio.com/_packaging/YYY/nuget/v3/index.json without any authorization token. That request ends with 401.


回答1:


The NuGet package credential and API key should be added in the NuGet.config file.

So before using the dotnet nuget push command, you should add the credential and API key in NuGet.config as below two commands:

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

Then push the NuGet package through the dotnet nuget push command:

dotnet nuget push packagename.nupkg --source mysource --api-key mykey


来源:https://stackoverflow.com/questions/48068329/push-a-nuget-package-to-vsts-with-net-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!