Creating a project for NUGET (C#)

What is NUGET?

NUGET is THE repository of projects of .NET (including C#)

It is integrated with Visual Studio but it is also possible to runs under CLI.

https://www.nuget.org/

A bit of stats

  • 21,145,360,813 package downloads
  • 1,696,723 package versions
  • 156,686 unique packages

Why do you want to publish a library on NUGET?.

Mainly because visibility but also to collaborate to the open source community.

Some people claim that they collaborate to the community but they are all barks but no bites. Sharing is caring.

Of course, we don't want to share our private project.

But Microsoft is Anti Open source is it?.

Microsoft is mainly closed-source but there are two trends of open source:

  • Full Open source. (Stallman & friends)
  • Mixed (open and closed-source)

Microsoft embraces the last one so it is fine.

Creating a new project using Visual Studio (Community)

In this example, I want to share a library called RutChile. It is a small library to work with the national Id (called RUT) from my country. I also published a repository on GitHub (also owned, I say pwned by Microsoft) https://github.com/EFTEC/RutChile

First, we need to create a new visual studio project

  • Create a project of the type: Class Library C# Standard. A standard library works with Net Framework and Core so it works for both.

Second, we create our library.

Third, we modify the properties of our project

  • Right button under our project - properties - packages

We will need a license but we could generate one online. I added the license as LICENSE.txt to my project.

We could also use a GitHub repository, where we could update an image and use as a repository but it is optional.

Fourth, we pack the project

It will generate a file called YOURPROJECT.1.0.0.nupkg. It is a zip file.

Fifth, we need a NUGET account

(https://www.nuget.org) it's easy to create one and it is for free.

Sixth. this part is tricky (but optional).

The nupkg generated has an incomplete file. Let's rename our *.nupkg project as .zip and open it.

There is a file called YOURPROJECT.nuspec, edit this file

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
  <metadata>
    ....
    <title>Rut Chile</title>
    <summary>Libreria para validar y generar RUT chilenos</summary>
    ....
  </metadata>
</package>

Inside "metadata", there are two tags that are missing "title" and "summary". Edit it manually, then rename your file back to .nupkg so you could upload it.

Seventh. Upload your library

https://www.nuget.org/packages/manage/upload

You could use a CLI to download it but it is a chore (keys and whatnot). It's way easy to use the website.

And finally, wait 15 minutes and that's it!.

https://www.nuget.org/packages/RutChile/

The library is up and running.

However, it could take a long while to be shared globally.

About Jorge Castro

Currently: Entrepreneur and Private Consultant
Civil Engineer in Informatics - USACH Chile.
Master in Business Administration (MBA) CEPADE Spain
Microsoft Certified Professional
Oracle Certified Associate
ScrumMaster Certified
Former developer
Former Project Manager

Related Posts