Introduction
NuGet is the most useful and essential tool for modern software development platforms via which developers can create, share and consume reusable code. Those useful or reusable common codes are compiled as DLLs and published as packages with code-related files and other information including the version number. As a developer, we are familiar with NuGet packages and use packages from the NuGet package manager. We all know that we can use any available NuGet package that is needed or suitable for our project from nuget.org. Anyone can build, publish and share the package through nuget.org. Furthermore, we can create a NuGet package using Microsoft Visual Studio and the .NET class library. Moreover, we can create open-source and non-open-source packages with license agreements.
In this article, we will create .NET 7 class library project and publish it as a NuGet package. Additionally, the article elucidates how we can create a NuGet package class library project, pack it using Visual Studio and upload it to nuget.org with an example and sample Logging code.
Prerequisites
- Visual Studio 2022
Follow the below steps:
Create .NET 7 Class Library Project
Step 1
Open Visual Studio and click on Create a new project.

Step 2
Select a C# Class Library project template as depicted below.

Step 3
Then, give a project name and directory of the project as shown below and click on Next.

Step 4
Select Framework: .NET 7.0 as illustrated below and click on Create.

After that, a default Class Library project will be created.
Step 5
Add a new Class Logger and write the below code.
Right-click on the project and click on Add option and then Class as shown below.

For the demo purpose, we will write a simple logging code to generate the log. Simple code to write the log of class, method, and an error message is given below, just copy and paste it into your Logger.cs file. However, you can write your program based on your package purpose and requirement.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoPackage
{
public class Logger
{
public void Log(string className, string methodName, string errorMessage)
{
Console.WriteLine("Class name:" + className);
Console.WriteLine("Method name:" + methodName);
Console.WriteLine("Error:" + errorMessage);
}
}
}
Now, our Logger program is ready, so we are ready to pack it. Before packing this project for NuGet we must configure the package property. Let’s configure the properties.









Felix LPosted Jan 17, 2023, 8:53 PM
Wow, that looks so easy. But how to use nuget for private projects? Do I need an extra Server running on localhost? Is there a solution from azure?
Joao MartinsPosted Jan 17, 2023, 3:10 PM
Well explained, thanks.
Hamid KhanPosted Jan 16, 2023, 3:20 PM
Good Article...
Innocent LangaPosted Jan 16, 2023, 12:36 PM
Exactly what i was looking for 2023, thanks for sharing.
Uday DodiyaPosted Jan 16, 2023, 6:13 AM
Good article..