Create NuGet Package with .NET

(Part One)

Ali Furkan Dadali
5 min readMar 3, 2022

Hello everyone, before starting let me give some preliminary information. I am trying to make my stories short as far as possible. Because time is the most valuable thing in life. When you have time to read my stories I try to do my best to use your time beneficial. 😊 This story will be a series including two-part. I will share part two on the following day.

Part One: Create and publish NuGet Package with .Net

Part Two: How to add your NuGet package in Azure Cloud Service?

What is NuGet?

I will try to explain an example, what is NuGet? You start to develop a new project and it is created by microservices architecture. You need to separate your business into the little parts and probably they will have common classes for the execute core tasks. If you add manually same classes (which for log or notification etc.) have a single responsibility, it would be a loss of time to recode and add the same classes every single time.

Imagine you turn these classes into a package for your solution as private or public. When you need it, just install it to your solution and call them with ‘using’ one line code. If there is a confidential issue you can share that just with your team and if you want to contribute and reach other programmers share on nuget.org 😇 Sounds exciting isn’t it? 🤓

So technically NuGet is a package manager for developers. Designed for the Microsoft Development platform.

You can find more detail about NuGet ->

Prerequisites

  • Visual Studio (I use version 2022 and .Net 6)
  • nuget.org account(It is free to sign up.)
  • If you want to add the package to your Azure service, you can create an account. You’ll have 30 days to use it — in addition to free services.

Let’s Create a NuGet Package!

The first step selects the project type. I want to create a Security package which is encryption and decryption classes. We can use that for the save password, DB connection parameters some credentials may be some confidential keys.

Select Class library and click next.

Give a name to the project.

I added my classes which are Encryption and Decryption.

I use System.Security.Cryptography library for these operations. After published.Net6 obsoleted some types in this library(like SYSLIB0021). Please follow this link to catch the last updates.

Encryption class.

Decryption Class

How does it work?

Our structure seems like

After added classes, we will make provision for the pack of our project into the NuGet package.

Go to properties of Security.Enigma Project.

Already have explanations about these inputs but I will give some details about how I fill inputs in this tab.

  • PackageId : Define your package name.
  • Package Version: Default value 1.0.0 if you add a new extension or option to your package when you update it also you can update your version here.
  • Description: also useful for the users. After you publish it developers can understand quickly what is used for.
  • Licencing: If you have a unique license you can add. If you don't describe it almost nobody will be able to use it. It is also changed in visual studio version 2022. MIT is the common one. Please check!
  • Icon Url: You can add icon. I think that makes them cute :)
  • Tags: It is also important to find your package from developers. You can put some keywords about your package.

After finishing to give those informations to our code we are ready to pack it.

Click right and pack it!

After completing the packing process you will have a notification on the output window.

If you copy created package URL which is end with .nupkg. This will make it easier to find a package while publishing.

Publishing

Go to nuget.org and sign in. On the profile tab, click the Upload Package.

Click the browse button and paste your package path which we copied from the output window. Before the publish you need to check your package information on the preview screen and if everything looks okay click the publish.

After clicking the publish button this screen will be waiting for you. It shows it might take a few minutes to a few hours. When your package is published NuGet will notify you.

Your package is published!

Also, You can search your package in the NuGet package solution on visual studio and include it in your project.

You can find the full project on my Github profile. https://github.com/furkandadali/Custom-NuGet-Packages

nuget.org package link: https://www.nuget.org/packages/Company.Security.Enigma/

Thanks for reading.

Feel free to comment and clap if you enjoyed ✌️

--

--