【问题标题】:How to use an API Key with dotnet restore with private NuGet server如何通过私有 NuGet 服务器将 API 密钥与 dotnet 还原一起使用
【发布时间】:2020-07-15 12:06:51
【问题描述】:

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

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

有没有一种方法可以为 dotnet restore 指定 API 密钥,或者是否可以将其作为查询参数包含在内(例如 https://mynuget.com?apikey=)?理想情况下,我想将 API Key 放在标题中。

【问题讨论】:

    标签: .net-core nuget-server dotnet-restore


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

      您可以通过在此处设置 CLI 键来找到好运:

      https://docs.microsoft.com/en-us/nuget/reference/cli-reference/cli-ref-setapikey

      【讨论】:

      • 抱歉,@Adam_Garner,但在 nuget.config 中设置 API 密钥似乎不适用于 nuget restore -Config &lt;config path&gt;
      猜你喜欢
      • 2012-05-25
      • 1970-01-01
      • 2013-01-17
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多