C#C
C#2y ago
Letieri

How to Implement Automatic Versioning for NuGet Package Using GitHub Actions?

Hello everyone,

I’m currently working on automating the release process for my NuGet package and would like to implement automatic versioning using GitHub Actions. I've managed to set up a workflow that builds and publishes the package to both GitHub Packages and NuGet.org, but I'm struggling to add the automatic version increment functionality.

Here's my current workflow:

name: Publish to GitHub Packages

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Setup .NET Core SDK
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: '8.0.x'

    - name: Build solution
      run: dotnet build Kayki.StringUtils.sln --configuration Release

    - name: Run tests
      run: dotnet test Kayki.StringUtilsTests/Kayki.StringUtilsTests.csproj --configuration Release

    - name: Build package
      run: |
          cd Kayki.StringUtils
          dotnet build -c Release -o out
          
    - name: Publish to GitHub Packages
      run: |
          cd Kayki.StringUtils/out
          dotnet nuget push *.nupkg --api-key ${{ secrets.PKG_TOKEN }} --source https://nuget.pkg.github.com/kaykiletieri/index.json --skip-duplicate

    
    - name: Publish to NuGet.org
      run: |
        cd Kayki.StringUtils/out
        dotnet nuget push *.nupkg --api-key ${{ secrets.PKG_NUGET_TOKEN }} --source https://api.nuget.org/v3/index.json --skip-duplicate
`
Was this page helpful?