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

在GitHub Action中配置GitVersion更新.NET Core API版本遇错求助

解决GitHub Actions中GitReleaseManager的uses属性格式错误及自动版本更新配置

错误原因分析

你碰到的错误是因为Publish release with GitReleaseManager步骤里的uses值格式不符合要求。GitHub Actions要求uses属性必须是路径、Docker镜像或者owner/repo@ref格式,你写的gittools/actions/gitreleasemanager/publishv0把动作路径和版本号混在了一起,正确写法应该是gittools/actions/gitreleasemanager/publish@v0,用@分隔路径和版本号。

修正后的完整GitHub Actions配置

---
name: CI/CD with Dependabot
on:
  pull_request:
    types:
      - opened
      - synchronize
jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        dotnet-version:
          - 6.0.x
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
        with:
          fetch-depth: 0 # GitVersion需要完整提交历史才能计算版本,必须加这个参数

      - name: Setup .NET Core
        uses: actions/setup-dotnet@v2
        with:
          dotnet-version: 6.0.x

      - name: Install GitVersion
        uses: gittools/actions/gitversion/setup@v0
        with:
          versionSpec: 5.x

      - name: Determine Version
        id: gitversion
        uses: gittools/actions/gitversion/execute@v0
        with:
          updateAssemblyInfo: true # 自动更新项目的AssemblyInfo版本信息

      - name: Restore
        run: dotnet restore "Mango.Web"

      - name: Build
        run: dotnet build "Mango.Web" --configuration Release --no-restore /p:Version=${{ steps.gitversion.outputs.fullSemVer }}

      - name: Publish
        run: dotnet publish "Mango.Web" --configuration Release --no-build /p:Version=${{ steps.gitversion.outputs.fullSemVer }}

      - name: Publish release with GitReleaseManager
        uses: gittools/actions/gitreleasemanager/publish@v0 # 修正此处的格式错误
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          owner: someOwner
          repo: your-repo-name # 补充你的仓库名称
          tagName: ${{ steps.gitversion.outputs.fullSemVer }} # 用GitVersion生成的版本号作为标签

  dependabot:
    name: Dependabot fetch metadata
    runs-on: ubuntu-latest
    if: ${{ github.actor == 'dependabot[bot]' }}
    steps:
      - name: Dependabot metadata
        id: metadata
        uses: dependabot/fetch-metadata@v1
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          skip-commit-verification: false

关键配置补充说明

  • Checkout步骤添加fetch-depth: 0:GitVersion依赖完整的Git提交历史来生成版本号,默认的checkout只拉取最新提交,必须加这个参数才能正常计算版本。
  • 自动同步项目版本:在Determine Version步骤开启updateAssemblyInfo: true,会自动更新项目的AssemblyInfo文件;同时在build和publish命令里通过/p:Version=${{ steps.gitversion.outputs.fullSemVer }}指定版本,确保编译后的程序集版本和GitVersion生成的一致。
  • 动态版本标签:把固定的tagName: 0.1.0换成GitVersion输出的版本号,实现版本标签和项目版本同步。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 08:50:19