使用 .NET CLI 将 NuGet 包推送到 VSTS [英] Push a NuGet package to VSTS with .NET CLI
问题描述
我正在尝试将 NuGet 包发布到私有 VSTS 源.我想使用 only .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>
我得到:<代码>错误:无法加载源 https://XXX.pkgs.visualstudio.com/_packaging/YYY/nuget/v3/index.json 的服务索引.错误:响应状态码不表示成功:401(未授权).
我可以在 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屋!