Member-only story
Creating NuGet Packages to Share Code
Sharing your useful code using packages

Most frameworks nowadays offer a set of components that is enough to build great applications, but on the other hand, they also provide a way to share our custom components to solve specific problems which most of the time allows the collaboration of the community to improve those pieces.
The .Net framework uses natively NuGet as a package manager for libraries such as Newtonsoft, Moq, Automapper, and many many others.
What many developers maybe do not know, is that creating and sharing a NuGet package with our code is extremely simple and quick and that is what I am going to explain in this article.
If you’re not a Medium paid member, you can read this story for free using the following link
What are we going to pack?
A couple of days ago I wrote an article about how we can intercept HTTP requests made using Refit and logging them as a curl and now I will use that code to create our new NuGet package.
We can find the whole code on this GitHub repo, under my profile.
I will adapt this code to be easily used by other developers in their projects.
Preparing the package
To create a NuGet package we need to first create a class library project, write the code, and run the command to generate the .nupkg
file with the package ready to be uploaded to nuget.org
First, run the command mkdir refit-log-calls
on the terminal to create a new folder and cd refit-log-calls
to access it.
Before creating a NuGet package is important to think about which .net core version we are going to target your library.
If you are using the latest version of .net core, projects using older versions would not be able to use your package.
You can check the installed dotnet version locally by running the command
dotnet --list-sdks
in my case I have these four:
Rundotnet new classlib
to create a new Class Library project, the last version will be used by default, if you want to override this and use an older version you must create a…