I have a solution for an ASP.NET Core API project that contains the main API project as well as two other library projects.
I now want to create NuGet packages for the library projects so that I can use them in other applications.
Do I need to separate my library projects into their own solutions and check them into their own separate repositories on GitHub in order to generate their NuGet packages through GitHub actions?
Currently the API and the library projects are in one solution and I keep them in the same repository. Do I need to split my projects into their own repositories or can I create NuGet packages only for my library projects from a single repository?
As per my experience, I suggest you to put the Nuget Application into another repository and follow the below instructions.
I've done this many times. Let me walk you through it.
Sign in to nuget.org then go to the API Keys management and create a key.
Go to GitHub and desired repository settings, then to Secrets. Create a new secret and paste there API key created on the first step.
Create a file under the root
< YOUR REPO > /.github/workflows/release.yml
name: Release to NuGet
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup .NET SDK
uses: actions/setup-dotnet@v1
- name: Build
run: dotnet build -c Release
- name: Test
run: dotnet test -c Release --no-build
- name: Pack nugets
run: dotnet pack -c Release --no-build --output .
- name: Push to NuGet
run: dotnet nuget push "*.nupkg" --api-key ${{secrets.nuget_api_key}} --source https://api.nuget.org/v3/index.json
It does:
Helpful Links: