Skip to content

Automatically updating NuGet packages #75

@VahidN

Description

@VahidN

Github supports actions with cron jobs. If you add GeneratePackageOnBuild to the .csproj to build a .nupkg file automatically, it's easy to push it to the NuGet server this way:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    </PropertyGroup>
name: .NET Core Build

on:
  push:
    branches: [ "main" ]
  schedule:
    - cron: "30 23 * * *"

    
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

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

    - name: Build library
      run: dotnet build ./UAParser/UAParser.csproj --configuration Release

    - name: Push Package to NuGet.org
      run: dotnet nuget push **\*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate

This is a sample .github\workflows\build.yml file's content with a cron job which executes every night and automatically builds the project, creates the nuget package and then sends it to the nuget server. The NUGET_API_KEY should be defined in the settings/secrets/actions section of this repository as a new Repository secret.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions