4

我正在尝试通过 NuGet 包管理器在 Visual Studio 2019 中提供一个 .NET Framework v4.5.2 包,该包来自 Github 的私有 NuGet 包注册表系统。

我正在使用的重要东西:

  • .NET 框架 4.5.2
  • Github 操作
  • Github
  • Github 包注册表 (GPR)
  • Visual Studio 2019/NuGet 包管理器

我的目标是什么?

整个生命周期看起来有点像这样:

  1. 我的项目的 repo 有一个 CI 工作(Github 品牌) to msbuild& publish nupkg。它将所有内容打包并将其部署到https://nuget.pkg.github.com/ <my-private-org>。
  2. 在 Visual Studio 2019 中,在给定项目破解打开的情况下,用户应该能够引用https://nuget.pkg.github.com/ <my-private-org> 作为自定义 NuGet 提要,并声明“我的项目”作为依赖。

什么有效,什么无效?

[Private] Failed to retrieve metadata from source 'https://nuget.pkg.github.com/<my-private-organization>/query?q=&skip=0&take=26&prerelease=true&supportedFramework=.NETFramework,Version=v4.7&semVerLevel=2.0.0'.
  Response status code does not indicate success: 401 (Unauthorized).

当我尝试GET https://nuget.pkg.github.com/<my-private-organization>/query?q=&skip=0&take=26&prerelease=true&supportedFramework=.NETFramework,Version=v4.7&semVerLevel=2.0.0'在浏览器中运行相同的查询(

{
  "errors": [
    { 
      "code" : "Your token has not been granted the required scopes to execute this query. The 'id' field requires one of the following scopes",
      "message":" ['read:packages'], but your token has only been granted the: [''] scopes. Please modify your token's scopes at: https://github.com/settings/tokens."
    }
  ]
}

我肯定有一个GITHUB_TOKENwith read:packageperms——在我的 CI 工作中,我首先用它来生成包。

我很怀疑...

我需要将我的read:package凭证GITHUB_TOKEN作为额外的 auth-credentials 传递,但我不知道是否/如何在nuget.config. 这导致我们...

我的配置是什么?

我读到我需要%APPDATA%/NuGet/nuget.config使用一些额外的凭据信息来参数化我,这些信息是从这里获得的:https ://docs.microsoft.com/en-us/nuget/reference/nuget-config-file#packagesourcecredentials 。我可以确认我正在更新正确的nuget.config文件——我已经能够在 Visual Studio 中使用我正在触摸的文件更改包流名称。现在看起来有点像:

<!-- file: nuget.config -->
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="Private" value="https://nuget.pkg.github.com/###############/index.json" />
    <add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\" />
  </packageSources>
  <packageSourceCredentials>
    <Private>
        <add key="Username" value="###############" />
        <add key="ClearTextPassword" value="*******************" />
        <!-- Could I perhaps need to introduce my Github Access Token here? -->
    </Private>
  </packageSourceCredentials>
</configuration>

中指定的用户名和密码packageSourceCredentials与我在浏览器中进行的手动GET查询中使用的相同(在 401 中失败)。

欢迎所有想法,即使是“没有人做A”。

4

1 回答 1

6

为了使用 Github 包源中的 nuget,您必须使用 GitHub 个人访问令牌,而不是您的 Github 用户名和密码。

阅读 GitHub 上的官方文档: https ://docs.github.com/en/free-pro-team@latest/packages/using-github-packages-with-your-projects-ecosystem/configuring-dotnet-cli-for -use-with-github-packages#authenticating-with-a-personal-access-token

使用本指南创建个人访问令牌: https ://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token

于 2020-11-11T08:33:07.613 回答