Every developer would talk about reusability of their code. They would talk about how they create classes where they define most of their functionalities and reuse them throughout their project.
But what if you have to reuse those classes in a different project entirely? Many would create a custom library and generate a DLL file. That is good but what if you have to share among your team and other developers? How would you keep track of the versioning?
It is always good to create NuGet packages for that part of your code which you might use in other projects or provide to others to utilize in their projects.
As usual, we would begin by creating a new project in Visual Studio of Class Library
On successfully creating your project, you will be presented with
Class1 as below
You can start adding your own classes and your functionalities as usual. For this article purpose, we will add a method for Addition and another for Multiplication.
Once your classes are created, it is time to configure NuGet package. For configuring NuGet package, right click on your Project (in Solution Explorer) and click on Properties and then click on Package.
You have to check the Generate NuGet package on build to generate the package whenever the project is built. After building your project, you can check in your bin folder (release or debug, depending on your configuration) and find the generated NuGet package
The versioning of your package can be handled from the properties window of your project as shown above.
There it is, your NuGet package. Now we will publish the NuGet package on nuget.org.
For publishing on NuGet, you would need to register using a Microsoft Account. Once you register and login, click on your username and go for Manage Packages.
And once you upload your NuGet package, it would ask for Readme, tags, etc. After entering the information, the package will be processed and available for download via nuget.org source from Visual Studio.