简体   繁体   中英

dotnet nuget push gives 401, but nuget.exe push succeeds

I've created a feed in Azure Artifacts, to which I want to publish Nuget packages. I have generated a Personal Access Token with the correct scope.

Running this command succeeds:

> nuget.exe  push -Source "myAzureFeed" -Apikey $(cat apikey) .\bin\Debug/MyPackage1.2.3.nupkg

Whereas, this command:

> dotnet nuget push .\bin\Debug\MyPackage.1.2.3.nupkg -s "myAzureFeed" -k $(cat apikey)

Gives me 401

PS D:\NuGet\create-package\using-dotnet-cli> dotnet nuget push .\bin\Debug\MyPackage.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).

Why does nuget.exe push succeeds and dotnet nuget push fails?

Why does nuget.exe push succeeds and dotnet nuget push fails?

There's already a GitHub ticket talking about this. See JeremyTCD's comment:

--api-key works for some feeds (eg Nuget.org) but not for others (eg Azure Artifacts feeds). For the latter kind of feed you need to specify password. Unfortunately password isn't accepted by the dotnet nuget or nuget CLIs so you have to set it in a nuget.config. Easiest way to update nuget.config is nuget sources add....

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. See dotnet nuget push for details.

So, before using the dotnet nuget push command, you should add the credential and API key in NuGet.config as below 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

You can also reference the samples instructed here: Publish packages from external sources to do that by running dotnet nuget comamnds.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM