简体   繁体   English

如何使用 API 密钥和私有 NuGet 服务器进行 dotnet 还原

[英]How to use an API Key with dotnet restore with private NuGet server

I've created a private NuGet server ( https://github.com/ai-traders/liget ) which requires an API key to upload packages but not to download/restore them.我创建了一个私有 NuGet 服务器( https://github.com/ai-traders/liget ),它需要一个 API 密钥来上传包但下载/恢复它们。

I am sure I can enhance the code of the server to mandate the use of an API Key when restoring, but the investigation I've done (mainly googling) hasn't yielded any examples of how an API Key can be specified for dotnet restore and the Visual Studio NuGet UI doesn't appear to allow it.我确信我可以增强服务器的代码以在恢复时强制使用 API 密钥,但我所做的调查(主要是谷歌搜索)没有产生任何关于如何为dotnet restore指定 API 密钥的示例并且 Visual Studio NuGet UI 似乎不允许它。

Is there a way of specifying an API Key for dotnet restore or is the only option to include it as a query parameter (eg https://mynuget.com?apikey= <API_KEY>)?有没有办法为 dotnet 恢复指定 API 密钥,或者是将其作为查询参数包含的唯一选项(例如https://mynuget.com?apikey >? Ideally I'd like to put the API Key in the header.理想情况下,我想将 API 密钥放在 header 中。

I discovered that you can't do this with an API key, but you can setup basic authentication on the NuGet server and use:我发现您不能使用 API 密钥执行此操作,但您可以在 NuGet 服务器上设置基本身份验证并使用:

dotnet nuget add source <nuget server> --name <name> --username <user> --password <password> --store-password-in-clear-text

This also works with Visual Studio.这也适用于 Visual Studio。 You'll get a dialog to enter the user name and password when you configure a new NuGet server.当您配置新的 NuGet 服务器时,您将看到一个对话框来输入用户名和密码。

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

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