Managing packages with NuGet

 Mar 20, 2015

NuGet is an open source package manager for the .NET Framework. NuGet makes it very easy for developers to add, remove and update library references in a project. It was first introduced in 2010 as an extension to Visual Studio 2010. Starting with Visual Studio 2012, NuGet is already included by default. It is also integrated into WebMatrix 3 and can also be used as an independent command-line utility, NuGet.exe, that you can download from here.

You can easily check if your installation of Visual Studio already has the NuGet extension by looking for the menu item NuGet Package Manager in the Tools menu of Visual Studio 2013. For older versions of Visual Studio, it was called Library Package ManagerIf this menu item is not there, you can select Extensions and Updates in VS 2013 or Extensions Manager with older versions of Visual Studio and then search for NuGet, and once you find it just click the Download button.

From the NuGet Package Manager group in the Tools menu, you can choose the graphical UI to manage your packages by clicking the menu item Manage NuGet Packages for Solution...this will open a dialog-box where you can search for packages and install them. If a package has dependencies, they will be downloaded and installed as well.

The UI is very convenient if what you want is the latest version of some library. But let's say you want to install a particular version of a library, for example version 5.0.0 of Entity Framework and not the latest version 6, which is known to cause problems when used with MVC4. In that case, you have to use the menu Package Manager Console. This Powershell-based console allows you to do much more than the UI option.

To uninstall the current version of the Entity Framework, you need to execute:

Uninstall-Package EntityFramework
To install version 5.0.0, enter:
Install-Package EntityFramework Version 5.0.0
If you want a list of installed packages in the current project, use:
Get-Package
In case you want a list of all available packages for download, you can add the flag -ListAvailable to the above command. You can also filter with -Filter followed by part of the name of a package. For example, to get a list of all packages, you can download that contains MVC in the name:
Get-Package -Filter Mvc -ListAvailable
If you want to update all the packages in your project to the latest available version, you need to execute the command:
Update-Package
If you add the -Safe flag to the above command, you will only update to latest version with the same major and minor numbers. For example 5.0.0 would be updated to 5.0.1 but not to 5.1 or 6.0.

To see more examples, you can visit the NuGet website and browse in the "Documentation" section.

How do your Excel skills stack up?   

Test Now  

About the Author:

Newton Godoy  

With over 17 years of in-class training experience and over 16 years of industry experience, Newton offers students a wealth of real-world technical knowledge and expertise in the areas of .NET application development, SQL Server and SharePoint Server. After spending several years lecturing as a professor, Newton found his true calling and began his career as a MCT. He worked as a technical trainer for some of Brazil's and Australia’s largest corporate training organisations before finally finding a home with New Horizons where he is now one of our top trainers. Newton brings a thorough mentoring capability to the classroom where he can advise on technical issues and challenges often beyond the scope of the course curriculum. His combination of technical knowledge and instructor experience make him one of the most respected instructors within the IT training industry.

Read full bio
top
Back to top