How to Install a NuGet Package in Visual Studio?


In this article, let’s see what is NuGet and how to install a NuGet Package in Visual Studio.

About NuGet

It is a free and open source package manager for the .NET Framework. It was formerly known as NuPack. The NuGet Gallery (nuget.org) is the central package repository used by all package authors and consumers.

When you install a package, NuGet copies all the required files to your project/solution and makes appropriate changes such as adding a reference to assembly, changing app.config or web.config file etc.

In short, You can include a Javascript file reference or add an assembly reference via NuGet Package Manager in Visual Studio. We don’t need to worry about dependent packages as it is automatically handled and included in the project by NuGet.

NuGet Package Manager Extension for Visual Studio

It is a collection of tools to automate the process of downloading, installing, upgrading, configuring, and removing packages from a Visual Studio Project/solution. It is distributed as a Visual Studio extension.

Installing NuGet Package Manager Extension

1. If the NuGet Package Manager is not installed on Visual Studio, you can install it by clicking on Tools > Extensions and Updates from the menu.

Clicking on “Extensions and Updates”, you will see following screen.

2. Select “Online” from the left hand side, you will see a list, sorted by Most popular packages. Select “NuGet Package Manager” from it and click on “Download” button to install it.

You will see following screens.

3. As show in the screen below, accept the license terms, click “Install” to continue.

Once installation is done, You will see this screen. Click on “Close” button.

4. You will be asked to restart the Visual Studio. Now you have NuGet Package Manager extension installed in Visual Studio. A small green checkbox icon is appeared against the installed extension.

More information about Nuget Package Manager extension can be found here in the visual studio gallery.

Installing NuGet Packages in Visual Studio

Basically there are 2 ways to install a NuGet Package in Visual Studio. First is via User interface window and other is via package manager console.

  • Installation via NuGet interface window

1. RIght click on your project from solution explorer and click on Manage NuGet Packages. Select the “Online” link from the left hand side and find the required package.

2. Click on “Install” button from the screen. Package manager will do all the stuff in the background for you.

2. If you see references in your project, reference for the installed package is added.

Here in this case, it’s json.NET package.

  • Installation via Package Manager Console

1. From the Tools menu, select Library Package Manager and then click Package Manager Console.

You will see following screen in Visual Studio.

2. To search a package, type a command Get-Package -ListAvailable -Filter <package name>

e.g Get-Package -ListAvailable -Filter EntityFramework

3. To install required package, type a command  Install-Package <package name>

e.g. Install-Package EntityFramework

Once installation done, you can see that reference for the package is automatically added to project.

NuGet Intro Video

4 thoughts on “How to Install a NuGet Package in Visual Studio?

Leave a comment