bao*_*uss 1 .net nuget github-actions github-package-registry
使用公共 NUGET.ORG 包以及我的组织自己的 nuget Github Packages 注册表中的包的项目可以在本地正常恢复,但无法在 Github Action 中执行此操作。以下是操作 yml 的摘录:
name: workflow1
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
packages: write
issues: write
steps:
- name: Check that shit out
uses: actions/checkout@v3
- name: Set that shit up
uses: actions/setup-dotnet@v2
with:
dotnet-version: '6.x.x'
- name: Build that shit
run: |
dotnet nuget add source https://nuget.pkg.github.com/myorg/index.json -n github -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text
dotnet restore ./project.sln
dotnet build ./project.sln --no-restore --configuration Release --nologo
Run Code Online (Sandbox Code Playgroud)
添加 nuget 源与此处推荐的(工作)相同。不幸的是,构建步骤失败并出现这样的错误
error NU***0***: Unable to find package <packageId>. No packages exist with this id in source(s): github, nuget.org
Run Code Online (Sandbox Code Playgroud)
我还尝试使用专用的 nuget.config 文件,而不是在运行时明确添加源。这也失败了,但奇怪的是,Github Packages 注册表甚至没有列出。
在其他工作流程中,我还使用 GITHUB_TOKEN 发布/写入 Gihub Packages 注册表。现在我只需要从中读取,但我想权限应该没问题。
你有什么想法为什么这会一直持续下去吗?任何帮助表示赞赏!谢谢。
现在自己解决了。在这里发帖,这样可能对其他人有用。
在项目根目录创建 nuget.config,包含一个packageSourceMapping部分。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<add key="github" value="https://nuget.pkg.github.com/myOrg/index.json" />
</packageSources>
<packageSourceMapping>
<packageSource key="github">
<package pattern="packageId" />
</packageSource>
<packageSource key="nuget">
<package pattern="*" />
</packageSource>
</packageSourceMapping>
</configuration>
Run Code Online (Sandbox Code Playgroud)
在 GH 操作执行中动态更新源的凭据
name: ci
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
issues: write
steps:
- name: Check that shit out
uses: actions/checkout@v3
- name: Set that shit up
uses: actions/setup-dotnet@v2
with:
dotnet-version: '6.x.x'
- name: Build that shit
run: |
dotnet nuget update source github -u ${{ github.actor }} -p ${{ secrets.READ_GH_PACKAGES_PAT_ORG }} --store-password-in-clear-text
dotnet restore ./project.sln
dotnet build ./project.sln --no-restore --configuration Release --nologo
Run Code Online (Sandbox Code Playgroud)
请注意,在我的情况下,我无法使用内置的${{ secrets.GITHUB_TOKEN }} ,必须自己创建一个,因为包含注册表的存储库是私有的而不是公开的。我还必须授权该令牌在我的组织内使用。
| 归档时间: |
|
| 查看次数: |
2520 次 |
| 最近记录: |