简体   繁体   English

错误 NU***0***: 找不到包<packageId> . 源中不存在具有此 ID 的包:github、nuget.org

[英]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.

相关问题 找不到 package Swashbuckle.AspNetCore。 源中不存在具有此 ID 的包:Microsoft Visual Studio 离线包 - Unable to find package Swashbuckle.AspNetCore. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages 发布 nuget package 内部可执行文件 nuget.org - Publish nuget package with executable inside, nuget.org 使用dotnet cli使用nuget.org的http版本还原项目的nuget软件包 - Restoring nuget packages of project with the http version of nuget.org using the dotnet cli Docker 中的 NuGet:错误 NU1301:无法加载源的服务索引 - 序列不包含任何元素 - NuGet in Docker: Error NU1301: Unable to load the service index for source - Sequence contains no elements 即使我已经从 NuGet.config 中删除了提要,Jenkins 也会从 nuget.org 下载 nuget 包 - Jenkins downloads nuget packages from nuget.org even though I have removed the feed from NuGet.config 如何通过 GitHub 操作在我的 dotnet 项目中使用 GPR 和 nuget.org 源? - How can I use GPR and nuget.org sources in my dotnet project via GitHub Actions? 无法为 Nuget 推送 GitHub Package - Unable to Push GitHub Package for Nuget 使用 dotnet 发布 .NET 5 和 win-x64 时出现错误“NU1101:无法找到 package xyz” - Error “NU1101: Unable to find package xyz” with dotnet publish .NET 5 and win-x64 NuGet 找不到package的版本 - NuGet unable to find the version of a package 使用 GitHub 操作发布 NuGet package 到 GitHub 包 - Publishing NuGet package to GitHub Packages Using GitHub Actions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM