【问题标题】:Incorrect Path and No API errors when trying to publish to GitHub packages via GitHubActions尝试通过 GitHubActions 发布到 GitHub 包时出现不正确的路径和无 API 错误
【发布时间】:2025-12-23 13:10:11
【问题描述】:

在这个问题上卡了很久,似乎是一个接一个的问题,只是试图让 GitHub Actions 将一个 nuGet 包发布到 GitHub 包,文档真的很难找到而且似乎没有给出任何明确例子

这是我之前的问题(仅用于上下文以防万一) I cant get gitHub actions to publish my package build to nuget.pkg.github

但现在,我得到以下信息:

Run dotnet nuget push "bin/Release/Project.1.0.0.nupkg" --source "github"
warn : No API Key was provided and no API Key could be found for 'https://nuget.pkg.github.com/name'. To save an API Key for a source use the 'setApiKey' command.
error: Could not find a part of the path '/home/runner/work/project/project/bin/Release'.

这是我完整的 yml

name: .NET Core

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 3.1.200
    - name: Install dependencies
      run: dotnet restore
    - name: Build
      run: dotnet build --configuration Release --no-restore
    - name: Test
      run: dotnet test --no-restore --verbosity normal
    - name: nuGet publish
      run: dotnet nuget add source https://nuget.pkg.github.com/name/index.json -n github -u uname -p password123 --store-password-in-clear-text
    - name: nuGet pack
      run: dotnet pack --configuration Release
    - name: publish
      run: dotnet nuget push "bin/Release/EurekaShared.1.0.0.nupkg" --source "github"

这是构建结果:

【问题讨论】:

  • 你试过dotnet nuget push "bin/Release/EurekaShared.1.0.0.nupkg" --source "github" -k "${{ secrets.GITHUB_TOKEN }}"吗? (见docs.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-push
  • 似乎.nupkg 文件不在您期望的位置。您能否将构建和打包步骤的输出日志添加到您的问题中。

标签: github github-actions


【解决方案1】:

dotnet nuget 很遗憾并不总是按预期工作,并且有返回误导性错误消息的习惯。真气。

尝试在您的工作流程中添加nuget/setup-nuget@v1 步骤并使用nuget.exe push 而不是dotnet nuget push。这可能会解决问题,或者至少会给您提供更有帮助的错误消息。

【讨论】:

    【解决方案2】:

    我认为该错误与nupkg 文件或文件名的路径部分有关。这可能是大小写问题,因为 Linux 区分大小写。

    此外,这个工作流文件只发布一​​个包,即EurekaShared.1.0.0.nupkg,如果你的包是EurekaShared.1.0.2.nupkg,它将不起作用

    也许您可以通过使用通配符 ** 更新 YML 文件中的最后一行来尝试一下,如下所示:

    run: dotnet nuget push /**/*.nupkg --source "github"
    

    我还建议您使用 GitHub 加密机密 https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets 保护工作流文件中的用户名和密码

    【讨论】:

      最近更新 更多