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

Github Actions部署NuGet遇MSB4044错误:GenerateDepsFile缺AssemblyVersion参数

解决GitHub Actions里dotnet build报MSB4044(AssemblyVersion缺失)的问题

问题情况

我写了个GitHub Actions脚本用来发布NuGet包,结果执行dotnet build步骤时触发错误:

MSB4044: The "GenerateDepsFile" task was not given a value for the required parameter "AssemblyVersion"

脚本中的build步骤代码:

- name: Build
  run: dotnet build OctaneEngine/OctaneEngine.csproj --no-restore --configuration Release /p:Version=${VERSION} /p:AssemblyVersion=${VERSION}

我已经做了以下操作但问题依旧:

  • 在build命令里手动指定了AssemblyVersion参数
  • 在项目的.csproj文件中禁用了GenerateAssemblyInfo,并定义了默认程序集版本1.0.0.0

排查方向&修复方案

1. Windows环境下环境变量引用格式错误

你使用的是windows-latest运行环境,GitHub Actions中通过echo "VERSION=..." >> $GITHUB_ENV设置的环境变量,在Windows的cmd环境下需要用%VERSION%引用,而非Linux/macOS环境的${VERSION}写法。

修改后的build步骤:

- name: Build
  run: dotnet build OctaneEngine/OctaneEngine.csproj --no-restore --configuration Release /p:Version=%VERSION% /p:AssemblyVersion=%VERSION%

2. 重复的restore步骤导致配置冲突

脚本中同时执行了dotnet restore和nuget restore,这两个步骤功能重复,容易导致项目配置或依赖信息被覆盖,进而影响版本参数的传递。直接移除单独的NuGet restore相关步骤即可,dotnet命令本身已包含restore功能,且与后续build步骤兼容性更好:

# 移除以下两个步骤:
- name: Setup NuGet.exe for use with actions
  uses: NuGet/setup-nuget@v1.0.5
- name: Restore NuGet
  if: steps.cacheStep.outputs.cache-hit != 'true'
  run: nuget restore Octane.sln

3. 项目文件中版本配置需明确

虽然你禁用了GenerateAssemblyInfo,但要确保.csproj文件中明确写死默认版本配置,避免MSBuild找不到默认值。检查项目文件是否包含如下配置:

<PropertyGroup>
  <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  <!-- 明确默认版本,确保命令行未传入参数时也有有效值 -->
  <Version>1.0.0.0</Version>
  <AssemblyVersion>1.0.0.0</AssemblyVersion>
  <FileVersion>1.0.0.0</FileVersion>
</PropertyGroup>

4. 验证环境变量是否正确设置

在build步骤前添加调试步骤,确认从tag提取的VERSION变量值是否正确:

- name: 查看VERSION变量值
  run: echo "当前版本是%VERSION%"

修复后的完整脚本片段

name: NuGet Publish

on:
  push:
    tags:
      - 'v*.*.*'
jobs:
  deploy:
    name: Deploy
    runs-on: windows-latest
    steps:
    - uses: actions/checkout@v2
    - name: Setup .NET
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 6.0.x
    - uses: actions/cache@v2
      id: cacheStep
      with:
        path: ~/.nuget/packages
        key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
        restore-keys: |
          ${{ runner.os }}-nuget-
    - name: Restore dependencies
      run: dotnet restore
    - name: 从tag提取版本号存入环境变量
      run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV
    - name: 调试版本变量
      run: echo "当前版本是%VERSION%"
    - name: 编译项目
      run: dotnet build OctaneEngine/OctaneEngine.csproj --no-restore --configuration Release /p:Version=%VERSION% /p:AssemblyVersion=%VERSION%
    - name: 发布NuGet包
      run: dotnet nuget push OctaneEngine/bin/Release/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 02:54:53