In this lesson, we're going to talk about NuGet, which is a Package Manager built into Visual Studio. The term “package” refers to any third-party library that you can import – and use to build applications – in your code. Package Managers can help you find, and manage, a plethora of freely available, open source projects that provide core functionality for your application. For example, why go off and build logging functionality when there are several good, open source logging utilities already available out there? You just need to download them, add them to your project, create a reference, and now you can use them inside of your project as if they were code that you’ve written yourself.
Installs files necessary to include a third party library/resource into your project.
Adds references to the class library files in your project.
Adds any dependencies, including other packages, that the target class library requires.
Updates the package, and its dependencies, to the latest version.
NuGet is a package manager that can run from command-line (for those used to using that kind of interface), as well as from a dialog in Visual Studio. You can browse, and download, available packages directly within Visual Studio, or download them from your web browser by going to:
To begin, create a new ASP.NET Web Forms application called NuGetExample, and add a Default.aspx page to the project. Navigate to the dialog utility for NuGet located at:
Tools > NuGet Package Manager > Manage NuGet Packages for Solution
Locate the latest version of “Bootstrap” from NuGet.org and install it into your project:
Make sure you search for the package source through “nuget.org,” and click OK to finish the process:
Once it successfully installs to your project you will see a green checkmark beside it in your package manager, while an update arrow might be visible to show an update is available for a related dependency:
Go ahead and update JQuery to the latest version:
You can view dependencies by clicking on the package in the Package Manager. The dependencies section should display at the bottom of the page. Here the Bootstrap package shows a dependency on JQuery, including the version required:
The JQuery package, on the other hand, has no dependencies:
You will also see the added package references in the Solution Explorer:
These package files and folders break down as follows:
“Content” contains the core CSS files for Bootstrap.
“fonts” contains common icons for resized mobile menu elements.
“packages.config” contains references to these packages within an XML configuration file.
Some may prefer using the Package Manger Console as another way of finding and installing packages. You get to this Console by selecting from the Visual Studio menu:
Tools > NuGet Package Manger > Package Manager Console
You can find a list of commands at: https://docs.nuget.org/consume/command-line-reference
You can also type in “get-help nuget” in the command line to get a list of commands;
Use the “Install-Package” command to install the popular logging utility called “Elmah”, a popular logging tool:
You should then see a list of actions indicating a successful install:
If you run the “Update-Package” command you may, or may not, see available updates:
Note that you can find the installed packages in the project folder under “packages”:
Lesson 66 - Package Management with NuGet