ASP.NET MVC-NuGet Package Management

In this chapter, we’ll talk about NuGet, which is a package manager for .NET and Visual Studio. NuGet can be used to find and install packages, i.e. parts of software and assemblies, as well as what you want to use in your project.

NuGet is not a project-specific tool ASP.NET MVC. This is a tool that you can use inside Visual Studio for console applications, WPF applications, Azure applications, and any type of application.

Package Management

NuGet is a package manager and is responsible for downloading, installing, updating, and configuring software on your system. By the term “software” , we do not mean end-user software such as Microsoft Word or Notepad 2, etc., but the parts of the software that you want to use in your project, links to assemblies.

For example, the assemblies that you want to use can be dummy assemblies for testing modular objects or NHibernate for data access, as well as components that you use when creating an application. The aforementioned components are open source software, but some of the NuGet packages you’ll find are closed source software. Some of the packages you found are even produced by Microsoft.

A common theme of all the packages mentioned above, such as mock and NHibernate, as well as Microsoft packages such as the Entity Framework preview, is that they don’t ship with Visual Studio by default.

Without NuGet

To install any of these components without NuGet, you will need the following steps.

If you want to use one of these components, you need to find the home page for a specific project and find the download link. Then, when the project is uploaded, it is usually in ZIP format, so you will need to unzip it.

If you haven’t downloaded the binaries, you will first need to build the software and then link to it in your project. And many components at this stage still require some configuration to get up and running.

Using NuGet

NuGet replaces all the steps described earlier, and you just need to say “Add package”. NuGet knows where to download the latest version, knows how to extract it, how to link to that component, and even configure it. This leaves you with more time to just build the software.

Let’s look at a simple example where we will add Entity Framework support to our project ASP.NET MVC using NuGet.

Step 1-Install the Entity Framework. Right-click on the project and select NuGet Package Manager → NuGet package Management for the solution…

The NuGet Package Manager opens.

Step 2-Search for Entity Framework in the search box.

Step 3-Select Entity Framework and click Install. The preview dialog box opens.

Step 4-Click Ok to continue.

Step 5-Click the “I accept” button to start the installation.

After installing Entity Framework, you will see a message in the out window, as shown above.

When you install a package with NuGet, you will see a new package directory in the same folder as the solution file that your project is located in. This package directory contains all the packages that you have installed for any of the projects in this solution.

In other words, NuGet does not upload packages to a centralized repository, but stores them separately for each solution.

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like
Read More

Components .NET

A well-designed web application written for ASP.NET, will include separate components that can be organized as separate data…