简体   繁体   English

dotnet nuget 推送给 401,但是 nuget.exe 推送成功

[英]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.我在 Azure Artifacts 中创建了一个提要,我想向其发布 Nuget 包。 I have generated a Personal Access Token with the correct scope.我已经使用正确的 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给我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?为什么nuget.exe push成功而dotnet nuget push失败?

Why does nuget.exe push succeeds and dotnet nuget push fails?为什么 nuget.exe 推送成功而 dotnet nuget 推送失败?

There's already a GitHub ticket talking about this.已经有一张GitHub 票在谈论这个。 See JeremyTCD's comment:请参阅 JeremyTCD 的评论:

--api-key works for some feeds (eg Nuget.org) but not for others (eg Azure Artifacts feeds). --api-key 适用于某些提要(例如 Nuget.org),但不适用于其他提要(例如 Azure 工件提要)。 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.不幸的是,dotnet nuget 或 nuget CLI 不接受密码,因此您必须在 nuget.config 中设置它。 Easiest way to update nuget.config is nuget sources add....更新 nuget.config 的最简单方法是 nuget 源添加....

The dotnet nuget push command pushes a package to the server and publishes it. dotnet nuget push 命令将 package 推送到服务器并发布。 The push command uses server and credential details found in the system's NuGet config file or chain of config files. push 命令使用系统的NuGet config file或配置文件链中的服务器和凭据详细信息。 See dotnet nuget push for details.详见dotnet nuget推送

So, before using the dotnet nuget push command, you should add the credential and API key in NuGet.config as below commands:因此,在使用dotnet nuget push命令之前,您应该在NuGet.config中添加凭据和 API 密钥,如下命令:

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推送命令推送NuGet package:

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.您还可以参考此处指示的示例:通过运行dotnet nuget comamnds 从外部源发布包来执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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