Create and publish a NuGet package using Visual Studio

We can create a nuget package by following these steps :

STEP 1 : Creating Visual Studio Project

Add a new visual studio project that contains a class library. We can add multiple libraries as well as per the need of your package.

Create and publish a NuGet package using Visual Studio

STEP 2 : Adding Code for Nuget

Start building your nuget package and add code. For current newsletter demo I am trying to create a Random Generator with some useful methods.

Create and publish a NuGet package using Visual Studio

This code and idea is just for the demo purpose.

STEP 3 : Announce that your Project is a Nuget Package

Let’s add some settings so visual studio should know that this is a Nuget Package.

Right click on your class library —> Click on properties.

You would see following screen : Create and publish a NuGet package using Visual Studio

Click on package tab now and start filling the information. For example package title, version, authors, company and description of package, icon, readme file, package license and repository etc.

I can not list down all, you can fill whatever you want to.

Don’t forget to check mark this , so on build a package file would be generated.

Create and publish a NuGet package using Visual Studio

Make sure that your package name is unique by searching it on nuget.org site.

STEP 4 : Build and Find Your Nuget Package File

Build the project by clicking on Build Tab at the top of Visual Studio. A nupkg file would be created now :

Create and publish a NuGet package using Visual Studio

We can double check that in folder as well : Create and publish a NuGet package using Visual Studio

STEP 5 : Publishing on Nuget Org

Visit Nuget Org and create your account if you have’t already. Your dashboard would look like this : Create and publish a NuGet package using Visual Studio

Click on Upload button and select nupkg file that we generated in previous step. Create and publish a NuGet package using Visual Studio

If everything goes fine you would be able to see this screen : Create and publish a NuGet package using Visual Studio

As you can see on top currently it is complaining about readme file and license, so you can resolve them by adding file and license.

After you click on Submit it will take a while and after that your package would be live.

You can verify that by clicking on your profile on right side —> Manage Package Create and publish a NuGet package using Visual Studio

GitHub Demo Code

Get demo code of this newsletter issue at my GitHub Repo

This article was originally published at https://mwaseemzakir.substack.com/ on .

Whenever you're ready, there are 3 ways I can help you:

  1. Subscribe to my youtube channel : For in-depth tutorials, coding tips, and industry insights.
  2. Promote yourself to 9,000+ subscribers : By sponsoring this newsletter
  3. Patreon community : Get access to all of my blogs and articles at one place