My first NuGet package — AppLogger


My first NuGet package — AppLogger

This is a short walk-through of publishing my first NuGet package. I implemented a very simple logger called AppLogger to demonstrate how to create and publish a NuGet package from a .NET project.

Why I built this

I wanted a compact example that shows the essential steps required to turn a .NET class library into a NuGet package consumers can install. The implementation is intentionally tiny — a Logger class that writes simple messages to the console — so the focus stays on packaging and publishing.

What the package contains

  • A minimal Logger class (AppLogger/Logger.cs) that exposes void Log(string message).
  • Package metadata in the project file (AppLogger/AppLogger.csproj) so the package is produced on build.
  • Documentation files included in the package root: README.md, CHANGELOG.md, and LICENSE.

Key snippets

Logger implementation (very small):

namespace AppLogger;

public class Logger
{
    public void Log(string message)
    {
        Console.WriteLine($"Log: {message}");
    }
}

Project packaging metadata (excerpt from AppLogger.csproj):

<PropertyGroup>
  <TargetFramework>net8.0</TargetFramework>
  <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
  <PackageVersion>1.0.0</PackageVersion>
  <PackageReadmeFile>README.md</PackageReadmeFile>
  <PackageLicenseFile>LICENSE</PackageLicenseFile>
  <RepositoryUrl>https://github.com/emirbuckun/NugetDemo.AppLogger</RepositoryUrl>
  <RepositoryType>git</RepositoryType>
</PropertyGroup>

<ItemGroup>
  <None Include="README.md" Pack="true" PackagePath="" />
  <None Include="LICENSE" Pack="true" PackagePath="" />
  <None Include="CHANGELOG.md" Pack="true" PackagePath="" />
</ItemGroup>

Build and pack

To build and produce a .nupkg file locally:

# from repository root
dotnet build AppLogger/AppLogger.csproj -c Release
dotnet pack AppLogger/AppLogger.csproj -c Release -o ./nupkgs

Then inspect the package to confirm the documentation files are included:

unzip -l nupkgs/*.nupkg

Publish to NuGet.org

To publish the package you'll need an API key from NuGet.org. Once you have it, publish with:

dotnet nuget push nupkgs/YourPackageId.1.0.0.nupkg --api-key YOUR_NUGET_API_KEY --source https://api.nuget.org/v3/index.json

Replace YourPackageId.1.0.0.nupkg with the actual filename produced by dotnet pack.

Note: it's possible to use dotnet pack with GeneratePackageOnBuild and CI pipelines to automatically create and push packages on releases.

Consume the package

Install the package into a project:

dotnet add package emirbuckun.NugetDemo.AppLogger --version 1.0.0

Use it in code:

using AppLogger;

var logger = new Logger();
logger.Log("Hello from the package!");

Repository, license and changelog

  • Repository: https://github.com/emirbuckun/NugetDemo.AppLogger
  • License: MIT — included as LICENSE in the package root
  • Release notes: see CHANGELOG.md included in the package root

Final notes and next steps

This package is deliberately tiny — its purpose is educational: to demonstrate the minimal steps required to create, pack, and publish a NuGet package from a .NET class library. Possible next steps:

  • Add unit tests and CI that runs dotnet pack and publishes on tags/releases.
  • Add simple logging configuration (log levels, output format).
  • Expand README with usage scenarios and API surface examples.

Thanks for reading — and congrats to me on publishing my first NuGet package! 🎉