AZ-400: Designing and Implementing Microsoft DevOps Solutions
Design and Implement a Package Management Strategy
Exploring GitHub Packages
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:
- Scaffold a .NET class library (
KodeKonvert
). - Configure NuGet package metadata in Visual Studio.
- Build and pack the library.
- Generate a GitHub Personal Access Token (PAT).
- Register GitHub Packages as a NuGet source.
- Push your
.nupkg
to GitHub Packages. - Consume the package in a new Blazor WASM project.
1. Scaffold the .NET Class Library
- Open Visual Studio.
- Create a new Class Library project.
- Rename the project to KodeKonvert.
- Target .NET 8.0 and confirm a successful build:
dotnet build
# success: 1 succeeded
2. Configure NuGet Package Metadata
In Solution Explorer, right-click KodeKonvert → Properties → Package. Set the following values:
Property | Value |
---|---|
Package ID | KodeKonvert |
Version | 1.0.0 |
Authors | KodeKloud |
Description | Simple library to convert temperature |
Generate NuGet package on build | ✔ Enabled |
Save and close the Properties pane.
3. Build and Pack the Library
From your terminal:
dotnet build --configuration Release
dotnet pack --configuration Release
You should see:
Successfully created package "bin/Release/KodeKonvert.1.0.0.nupkg".
Remember the full path to the generated .nupkg
file for later steps.
4. Generate a GitHub Personal Access Token
- In GitHub, navigate to Settings > Developer settings > Personal access tokens.
- Click Generate new token (classic or fine-grained).
- Assign minimal scopes:
read:packages
write:packages
repo
(only if you publish from a private repo)
- Copy the token once when presented.
Note
Store your PAT securely; you’ll need it to authenticate your NuGet source and to push packages.
5. Register GitHub Packages as a NuGet Source
Add the GitHub Packages feed to your NuGet configuration:
dotnet nuget add source \
--username YOUR_GITHUB_USERNAME \
--password YOUR_PERSONAL_ACCESS_TOKEN \
--store-password-in-clear-text \
--name github \
https://nuget.pkg.github.com/YOUR_GITHUB_USERNAME/index.json
Warning
Using --store-password-in-clear-text
will save your PAT in plain text. Ensure your machine is secure.
Verify the source:
dotnet nuget list source
6. Publish the Package
Push the .nupkg
to your GitHub Packages feed:
dotnet nuget push bin/Release/KodeKonvert.1.0.0.nupkg \
--source github \
--api-key YOUR_PERSONAL_ACCESS_TOKEN
Expected output:
Pushing KodeKonvert.1.0.0.nupkg to 'https://nuget.pkg.github.com/YOUR_GITHUB_USERNAME'...
OK https://nuget.pkg.github.com/YOUR_GITHUB_USERNAME/ 380ms
Your package was pushed.
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
- Create a Blazor WebAssembly project:
dotnet new blazorwasm -o testweb
cd testweb
- Ensure the GitHub NuGet source is available:
dotnet nuget list source
- Add your package:
dotnet add package KodeKonvert --version 1.0.0
Sample output:
info : Adding PackageReference for package 'KodeKonvert' into project 'testweb.csproj'.
info : Installed KodeKonvert 1.0.0 from https://nuget.pkg.github.com/YOUR_GITHUB_USERNAME/...
You can now call KodeKonvert
APIs in your Blazor components.
References
Watch Video
Watch video content