[英]error NU***0***: Unable to find package <packageId>. No packages exist with this id in source(s): github, nuget.org
A project that useses public NUGET.ORG packages and also packages from my Org's ownnuget Github Packages registry restores just fine locally, but fails to do so inside a Github Action.使用公共 NUGET.ORG 包以及我的 Org 自己的 nuget Github 包注册表中的包的项目在本地恢复得很好,但在 Github 操作中无法这样做。 Here's the exerpt from the action's yml:
以下是动作 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
Adding the nuget source is the same as recommended (as working) here .添加 nuget 源与此处推荐的(作为工作)相同。 Unfortunately the Build step fails with an error like this
不幸的是,构建步骤失败并出现这样的错误
error NU***0***: Unable to find package <packageId>. No packages exist with this id in source(s): github, nuget.org
I have also tried using a dedicated nuget.config file instead of expicitly adding the source on the run.我还尝试使用专用的 nuget.config 文件,而不是在运行时显式添加源。 This also fails, but curiously, the Github Packages registry is not even listed.
这也失败了,但奇怪的是,Github Packages 注册表甚至没有列出。
In other workflows I am also using the GITHUB_TOKEN to publish/write to the Gihub Packages registry.在其他工作流程中,我还使用 GITHUB_TOKEN 发布/写入 Gihub Packages 注册表。 Now I only need to read from it, but the permissions should be okay I guess.
现在我只需要从中读取,但我猜权限应该没问题。
Any thoughts on why this keeps crahing?关于为什么这一直崩溃的任何想法? Any help is appreciated!
任何帮助表示赞赏! Thanks.
谢谢。
Solved it now by myself.现在自己解决了。 Posting here so it might be useful for someone else.
在这里发帖,可能对其他人有用。
create nuget.config at project root, include a packageSourceMapping
section.在项目根目录创建 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>
update the source's credentials on-the-fly in the GH action's execution在 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
Note, that in my case I couldn't use the built-in ${{ secrets.GITHUB_TOKEN }}
and had to create one myself, since the repo containing the registry is private and not public.请注意,在我的情况下,我不能使用内置的
${{ secrets.GITHUB_TOKEN }}
并且必须自己创建一个,因为包含注册表的存储库是私有的而不是公共的。 I also had to authorize the token for use within my organisation.我还必须授权令牌在我的组织内使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.