.net - 如何使用 Visual Studio 2019 设置私有 Nuget 包注册表?
问题描述
我正在尝试通过 NuGet 包管理器在 Visual Studio 2019 中提供一个 .NET Framework v4.5.2 包,该包来自 Github 的私有 NuGet 包注册表系统。
我正在使用的重要东西:
- .NET 框架 4.5.2
- Github 操作
- Github
- Github 包注册表 (GPR)
- Visual Studio 2019/NuGet 包管理器
我的目标是什么?
整个生命周期看起来有点像这样:
- 我的项目的 repo 有一个 CI 工作(Github 品牌) to
msbuild
& publishnupkg
。它将所有内容打包并将其部署到https://nuget.pkg.github.com/ <my-private-org>。 - 在 Visual Studio 2019 中,在给定项目破解打开的情况下,用户应该能够引用https://nuget.pkg.github.com/ <my-private-org> 作为自定义 NuGet 提要,并声明“我的项目”作为依赖。
什么有效,什么无效?
GitHub成功发布了我的包——我可以在访问https://github.com/my-private-organization?tab=packages时看到它。
但是,我无法让 Visual Studio 2019 支持我的私有 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_TOKEN
with read:package
perms——在我的 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”。
解决方案
为了使用 Github 包源中的 nuget,您必须使用 GitHub 个人访问令牌,而不是您的 Github 用户名和密码。
使用本指南创建个人访问令牌: https ://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token
推荐阅读
- azure - 如何将数据从 .net 核心 api 发送到 azure 日志分析
- python - Python如果mysql行不等于输入
- reactjs - 从 MapContainer 外部渲染 Map 子节点
- azure - @azure/identity node.js 无法进行身份验证
- redis - Redis 集群问题
- checkbox - 单击时 SwiftUI 复选框未显示复选标记
- apache-spark - 将 Spark DataFrame 写入 Kafka 是忽略分区列和 kafka.partitioner.class
- node.js - Json.parse 抛出:“SyntaxError:JSON 输入意外结束”
- vb.net - 访问 VB.net DataGridView== > 错误消息:“没有为一个或多个必需参数提供值。”
- mysql - 在子查询中使用主查询中的值