NuGet Manager : Package Install and Uninstall

NuGet is commonly used as Microsoft Visual Studio Extension and helps various developers across the globe to create and consume packages. Its easy, convenient and hassle free. The scope of this article is to make you aware about NuGet and how one can consume a package. We will mainly learn about Installing/Consuming a package and then Uninstalling/Removing the package. Lets talk more about it.

NuGet Manager Package Install & Uninstall How & Why

What Is NuGet?

NuGet is the package manager for the Microsoft development platform including .NET. The NuGet client tools provide the ability to produce and consume packages to the developers. The NuGet Gallery is the central package repository that is used by all package authors and consumers.

Why NuGet Is Used?

Using NuGet the developers can consume the already available packages in NuGet Gallery. When a package is consumed, NuGet makes all the necessary changes like copying the package files to the solution and adding the references in the project. Also it updates your config files if changes are needed. Now lets learn more about managing a package for a solution. 

How to Use NuGet?

First you should be having NuGet Manager installed in your Visual Studio. If not, just goto Menu>Tools>Extensions & Updates, search for NuGet Manager and Install it.

Now assuming you have you NuGet Manager in place, lets see how to use it.
We have created a New ASP .Net Application with the name of NuGetApplication. There is a file named packages.config in the project. It is automatically added. It contains information about all the packages installed.
Solution Explorer Showing packages.config for nuget

Shown below is the content of the packages installed for this project.
It specifies the package id, their version and the target framework which is .Net 4.0 in our case.

packages.config file showing all installed packages

Now before learning how to consume a package, lets start with how to remove a package as their are plenty of packages pre-installed with our NuGetApplication.

How To Remove A Package In NuGet?

Open NuGet Manager, goto Menu>Tools>NuGet Package Manager>Manage NuGet Packages for Solution. A window will appear just like shown below

Nuget Package Manager Installed Packages

In this we have selected Modernizr as the one to be removed. Now there is a button that says Manage. Upon clicking this button a confirm window will appear.
Manage Nuget Packages

This window has a list of all the projects present in our solution. This will remove the package from all those projects in which we uncheck the checkboxes. This way we can also install the package to another project of same solution just by checking the checkbox.

Now we unchecked the checkbox infront of NuGetApplication project and clicked OK. This process removes the reference of Modernizr from project and also removes the entry from packages.config. You can do same steps to learn it.

How to Consume A Package In NuGet?

Open NuGet Manager, goto Menu>Tools>NuGet Package Manager>Manage NuGet Packages for Solution. 
Now click on Online tag on the left panel of window and now search for Modernizr as we just removed it, so you can relate to it. The search result will show like below

Nuget Package Manager Search Result Modernizr

Now click on Install and same window will appear with checkboxes for projects. Upon clicking OK the package will be installed for selected projects and references, packages.config will be updated accordingly.

How To Downgrade To A Previous or Older Version Of A Package?

While using package manager, there is a problem that you can't get a specific version of a package. Because it always shows us the latest version of a package. If you want to downgrade to a specific version then you can use packages.config file.
In packages.config file with the name of the package there's is an attribute of version. To downgrade to a specific version, just alter the version to your desired package and build your solution. Then package will automatically downgrade and all the changes will be done in project automatically.

Check our video on Nuget Manager & Its Usage

That's all about Consumption & Removal of Package through NuGet Manager.
Feel free to comment. 

Happy Learning!!!


Popular posts from this blog

Just Maths - Views, View Groups and Layouts

Create Android Apps - Getting Started