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.
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 Repo
Whenever you're ready, there are 3 ways I can help you:
- Subscribe to my youtube channel : For in-depth tutorials, coding tips, and industry insights.
- Promote yourself to 9,000+ subscribers : By sponsoring this newsletter
- Patreon community : Get access to all of my blogs and articles at one place