Push a NuGet package to VSTS with .NET CLI
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
Jakub Binkowski
Updated on June 23, 2022Comments
-
Jakub Binkowski almost 2 years
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. -
Jakub Binkowski over 6 yearsThanks. I was looking for an option that: a) doesn't require to store the keys in NuGet config as I wanted to check in the file to repository b) doesn't require nuget.exe But I guess, it can't be done (yet?)
-
Marina Liu over 6 yearsYeah, it can not be done. The credentials should be searched in nuget.config file as the description docs.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-push says: "The
dotnet nuget push
command pushes a package to the server and publishes it. The push command uses server and credential details found in the system's NuGet config file or chain of config files. " -
Alex Mullans over 6 yearsNote that you won't need either the setapikey line or the --api-key parameter when pushing to VSTS Package Management. Otherwise though, the answer is correct. You can manually construct a NuGet.config without using nuget.exe, if you'd like. There's a reference here that can help: docs.microsoft.com/en-us/nuget/schema/…
-
Andre Soares about 6 yearsYou have used
mykey
andPAT
. I suppose they do not represent the same value. How then can I generate thismykey
? -
KimCM almost 6 years@Andre Soares: Yes, mykey and PAT do not represent the same value: "The NuGet client's push command requires an API key. [With VSTS Package Server] You can use any non-empty string you want". Source: docs.microsoft.com/en-us/vsts/package/nuget/publish?view=vsts
-
Konrad almost 6 years@MarinaLiu-MSFT is
nuget setapikey mykey
needed? when you use--api-key mykey
-
Konrad almost 6 years"Saves an API key for a given server URL into NuGet.Config so that it doesn't need to be entered for subsequent commands."
-
Konrad almost 6 yearsIt would mean that I don't need to use
--api-key mykey
then -
Konrad almost 6 yearsoh nevermind I didn't read all comments, it was answered by Alex
-
christopher clark over 5 yearsI'm convinced none of microsofts shitty vsts tasks work for nuget. Every avenue we try there are issues.
-
Ricardo stands with Ukraine about 3 yearsIn my case had to push a package to GitHub Package Registry so did:
nuget setapikey <github-token-with-repo-permissions> -source github
. It added some gibberish to%appdata%\NuGet\NuGet.Config
and then could push the package.