使用.NET CLI将NuGet包推送到VSTS [英] Push a NuGet package to VSTS with .NET CLI
问题描述
我正在尝试将NuGet包发布到私有VSTS供稿.我想仅使用 .NET CLI来实现,而无需创建或修改nuget.config文件.
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.
我试图做:
dotnet nuget push <PackageName> --source https://XXX.pkgs.visualstudio.com/_packaging/YYY/nuget/v3/index.json --api-key <VSTS UserName>:<PersonalAccessToken>
我得到:
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 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).
我在Fiddler中看到,.NET CLI仅向https://XXX.pkgs.visualstudio.com/_packaging/YYY/nuget/v3/index.json
发送GET请求,而没有任何授权令牌.该请求以401结尾.
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.
推荐答案
应该在NuGet.config
文件中添加NuGet软件包凭据和API密钥.
The NuGet package credential and API key should be added in the NuGet.config
file.
因此,在使用dotnet nuget push
命令之前,您应该在NuGet.config
中添加证书和API密钥,如下所示,这是两个命令:
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
然后通过dotnet nuget push
命令推送NuGet软件包:
Then push the NuGet package through the dotnet nuget push
command:
dotnet nuget push packagename.nupkg --source mysource --api-key mykey
这篇关于使用.NET CLI将NuGet包推送到VSTS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!