Skip to main content
GitHub Packages enables you to host and manage code dependencies alongside your repositories. In this guide, we’ll walk through publishing a .NET class library to GitHub Packages and consuming it in a Blazor WebAssembly app. In this tutorial, you will:
  1. Scaffold a .NET class library (KodeKonvert).
  2. Configure NuGet package metadata in Visual Studio.
  3. Build and pack the library.
  4. Generate a GitHub Personal Access Token (PAT).
  5. Register GitHub Packages as a NuGet source.
  6. Push your .nupkg to GitHub Packages.
  7. Consume the package in a new Blazor WASM project.

1. Scaffold the .NET Class Library

  1. Open Visual Studio.
  2. Create a new Class Library project.
  3. Rename the project to KodeKonvert.
  4. Target .NET 8.0 and confirm a successful build:

2. Configure NuGet Package Metadata

In Solution Explorer, right-click KodeKonvertPropertiesPackage. Set the following values:
The image shows a Visual Studio interface with a project named "KodeKonvert" open. It displays the package settings for generating a NuGet package, including fields for Package ID, Title, Version, and Authors, along with a build output at the bottom.
Save and close the Properties pane.

3. Build and Pack the Library

From your terminal:
You should see:
Remember the full path to the generated .nupkg file for later steps.

4. Generate a GitHub Personal Access Token

  1. In GitHub, navigate to Settings > Developer settings > Personal access tokens.
  2. Click Generate new token (classic or fine-grained).
  3. Assign minimal scopes:
    • read:packages
    • write:packages
    • repo (only if you publish from a private repo)
  4. Copy the token once when presented.
Store your PAT securely; you’ll need it to authenticate your NuGet source and to push packages.
The image shows a GitHub page for creating a new personal access token, with options to set a note, expiration, and select various scopes for permissions.

5. Register GitHub Packages as a NuGet Source

Add the GitHub Packages feed to your NuGet configuration:
Using --store-password-in-clear-text will save your PAT in plain text. Ensure your machine is secure.
Verify the source:

6. Publish the Package

Push the .nupkg to your GitHub Packages feed:
Expected output:
The image shows a GitHub settings page for managing personal access tokens, with options to generate new tokens and view existing ones. It includes details about token usage and expiration dates.
Head over to your repository’s Packages section to confirm that KodeKonvert v1.0.0 is listed.

7. Consume the Package in a Blazor WASM App

  1. Create a Blazor WebAssembly project:
  1. Ensure the GitHub NuGet source is available:
  1. Add your package:
Sample output:
You can now call KodeKonvert APIs in your Blazor components.

References

Watch Video