If you find value in my newsletter and wish to offer support, consider becoming a Patreon. I've extensively covered over 180 .NET topics with accompanying code, consolidating valuable insights in one comprehensive resource.
Your contribution ensures the continued creation of high-quality content and access to a wealth of curated information.
About today’s newsletter :
Today we are going to discuss :
How to create a nuget package
How to publish it on nuget.org
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.
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.
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 :
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.
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 :
We can double check that in folder as well :
STEP 5 : Publishing on Nuget Org
Visit Nuget Org and create your account if you have’t already. Your dashboard would look like this :
Click on Upload button and select nupkg file that we generated in previous step.
If everything goes fine you would be able to see this screen :
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
GitHub Demo Code
Get demo code of this newsletter issue at my GitHub Repository
Whenever you’re ready, there are 2 ways I can help you
Promote yourself to 8200+ subscribers by Sponsoring my Newsletter
Get a FREE eBook from Gumroad that contains 30 .NET Tips (2900+ downloads)