You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Actions打包NuGet遇NU5026错误:目标DLL文件缺失

解决GitHub Actions中dotnet pack找不到dll的问题

问题分析

你遇到的错误根源在于dotnet pack命令默认不会自动构建项目,而GitHub Actions的运行环境是全新的,没有预先生成的编译产物(比如MyNugetPackage.dll)。本地能成功是因为你已经手动构建过,生成了Release目录下的文件,但CI环境里缺少这一关键步骤。

修复方案

修改create_nuget任务,在打包前添加还原依赖和构建项目的步骤,确保编译产物生成后再执行打包:

create_nuget:
  runs-on: ubuntu-latest
  steps:
  - uses: actions/checkout@v3
    with:
      fetch-depth: 0 # Get all history to allow automatic versioning using MinVer

  - name: Setup .NET
    uses: actions/setup-dotnet@v3

  - name: Restore dependencies
    run: dotnet restore

  - name: Build project
    run: dotnet build --configuration Release --no-restore

  - name: Pack NuGet package
    run: dotnet pack --configuration Release --no-build --output ${{ env.NuGetDirectory }}

  - uses: actions/upload-artifact@v3
    with:
      name: nuget
      if-no-files-found: error
      retention-days: 7
      path: ${{ env.NuGetDirectory }}/*.nupkg

关键说明

  • dotnet restore:还原项目依赖,确保所有NuGet包都已下载完成
  • dotnet build --no-restore:用Release配置构建项目,--no-restore避免重复执行还原步骤,提升效率
  • dotnet pack --no-build:基于已构建的产物打包,--no-build防止重复构建,同时确保使用刚生成的dll文件

额外检查项

  1. 确认你的项目文件(.csproj)中已正确指定TargetFramework:
<TargetFramework>net6.0</TargetFramework>
  1. 如果使用MinVer自动版本控制,确保项目文件中已正确配置MinVer相关属性,比如:
<PropertyGroup>
  <MinVerTagPrefix>v</MinVerTagPrefix>
</PropertyGroup>

内容的提问来源于stack exchange,提问作者Hakuna

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 08:44:58