NuGet is a package management system for the .NET platform, it is supposed to simplify the process of incorporating third-party libraries into a .NET project during development. Basically, it is a great way to add (and update) open source libraries and the like to your .NET project. The first version of NuGet was released in October 2010 and it was originally named NuPack.
How to get it
NuGet can be installed from here or from Visual Studio’s Extension Manager located under the Tools menu.
The awesomeness of it
Before NuGet, the way we incorporated third-party libraries into our projects was by doing the following:
- Download third-party library (and any dependencies) from the web.
- Unpack them (as many of them come in compressed files) to a folder in our project, I usually create (or created) a folder labeled “lib” and placed all the third-party libraries there.
- Import to the .NET project.
- Make any necessary changes to the config file when needed.
If a new version of NUnit became available and you wanted to use it in your project, you’ll just need to type the following command in the Package Manager Console to update NUnit using NuGet: PM> Update-Package nunit
The NuGet Gallery
Where does this copy of NUnit comes from you might ask? if you look closely at the image above, you’ll see a Package source field in the upper left corner of the window, this is the default NuGet package source and it basically points to NuGet’s service at http://packages.nuget.org/v1/FeedService.svc/.
These third-party libraries are hosted by Microsoft and the list of third-party libraries available in NuGet increases every day.
As of today, there are 1,418 packages available in NuGet’s official package service. You can browse the different packages available in NuGet by visiting the NuGet website, by opening the Add Library Package Reference located under the Tools menu (Tools – Library Package Manager), the Add Library Package Reference is also available in the Add Reference menu, and my favorite, by typing the command PM> Get-Package -ListAvailable in the Console… if you do this, just have in mind that it will take a while to list all the libraries available
For those that prefer the clicking instead of the typing, the Package Manager Console (UI) is your tool, below is a screen shot of what it looks like:
From this window, you can see a list of the installed packages, a list of all the packages available, you can search and install any package you might need to as well; this is all in a per-project basis. What this means is that if you have a solution with multiple projects and you want to have a library such as NUnit available to all projects or at least available in more than one project… you’ll have to add it to each individual project – yes! this isn’t ideal, I know.
Phil Haack, Senior Program Manager for the ASP.NET team, recently wrote about the possibility of adding the ability to use a single package version per solution, instead of project. I think this is a great idea and many people probably won’t start using NuGet in their multi-project solutions until this is available. Phil or @haacked for those who follow him on Twitter, also took the time to add a survey to his blog post and based in the results of this survey, it looks like the majority of the people who responded agree that having the option to have a single NuGet package version per solution is not only ideal, it is necessary.
How to Contribute
You can develop your own NuGet packages and upload them to NuGet.org so they can be shared with others, all you need to do this is to create an account on NuGet.org and then upload your NuGet package. Detailed instructions on how to create a NuGet package can be found here.
The team working in NuGet seems to be very active and new versions are coming out often, they just released a new version of NuGet about a week ago and these are the steps in order to update to the latest version, NuGet 1.3
To update from the Extension Manager
Go to the Tools menu in Visual Studio, click on Extension Manager and you’ll see the window below:
To update NuGet.exe
With this release comes also a new version of NuGet.exe, this is the same tool that package authors have been using to create packages and upload them to NuGet gallery. If you haven’t downloaded it yet, you can get the latest version from NuGet’s CI server here. After you download it, and once a new version comes out, to update you’ll only have to type the following nuget.exe u command as shown below:
You can read all the changes, updates and new features released with NuGet 1.3 here.
Well, that is all I have now regarding NuGet, I do like this tool and I think it will be very useful for all .NET developers. I am working in another post that will show the steps to follow to create your own nuget server/gallery (yes, the code for the nuget service is open source and available to anyone interested!), upload your own nuget packages and make them available to your team. The idea is that a company developing in the .NET platform can take advantage of having their own nuget service running internally so their developers can share their own class libraries and the like by using nuget and their local nuget service/gallery. This is better than shared network folders, emailing dlls, etc…