如何通过私有 NuGet 服务器使用 API 密钥进行 dotnet Restore

Pau*_*yer 8 nuget-server .net-core dotnet-restore

我创建了一个私有 NuGet 服务器(https://github.com/ai-traders/liget),它需要 API 密钥来上传包,但不需要下载/恢复它们。

我确信我可以增强服务器的代码以在恢复时强制使用 API 密钥,但我所做的调查(主要是谷歌搜索)尚未提供任何有关如何指定 API 密钥dotnet restore以及Visual Studio NuGet UI 似乎不允许这样做。

有没有办法为 dotnet 恢复指定 API 密钥,或者是将其作为查询参数包含的唯一选项(例如https://mynuget.com?apikey= <API_KEY>)?理想情况下,我想将 API 密钥放在标头中。

Pau*_*yer 11

我发现您无法使用 API 密钥执行此操作,但您可以在 NuGet 服务器上设置基本身份验证并使用:

dotnet nuget add source <nuget server> --name <name> --username <user> --password <password> --store-password-in-clear-text
Run Code Online (Sandbox Code Playgroud)

这也适用于 Visual Studio。配置新的 NuGet 服务器时,您将看到一个对话框,用于输入用户名和密码。