This tutorial looks at how to use the NuGet package manager to install packages in three individual projects. You’ll see how to get open the Nuget gallery from the IDE. Learn how to read the meta-data for each project and see a quick example of how Nuget packages can modify a web.config file.
- [Voiceover] It's time to look at how to use the package manager to install packages. First let's look at the projects in the solution. I have TinyAsp, TinyDesktop, and TinyWeb inside this install solution. Each project is a minimal one. I created it to have very few files or references hence the name tiny. Because the projects are so simple, it's easy to see the changes made by NuGet. TinyDesktop, and TinyWeb are very small, created using the empty CSharp project template. There's just a few references, there's one reference here.
And there's an App.config file, same in the TinyWeb. TinyAsp is a Asp.net 4.6 project made with the empty Asp.net template. You can see that it has the standard Asp.net list of references and it has a packages.config, and a web config file. I'll start by adding a package to TinyDesktop. I'll right-click and choose manage NuGet package. Now this is going to manage the package for one project only.
I'll choose the default source for my packages NuGet.org, this is the Microsfot NuGet gallery and you can see that I have no installed packages. Says the installed section, there's no installed packages. So I'll click on the browse section and look at some of the available packages. This one looks interesting AutoMapper. This is the library built to automate the creation of code that maps one object of properties to another. This type of code is monotonus to write using AutoMapper solves this problem in an elegant way.
To install it, I would click on this install button. But let's talk about what happens during the install. NuGet grabs the package from the Microsoft gallery and copies it to my hard drive. It puts one copy in the NuGet cache, and another copy in my solution. In the future, if I want to install AutoMapper into another project, NuGet will fetch it from the local NuGet cache instead of downloading it from the internet. Alright, I'll click the install button and you can see some information in the output window that it resolved some actions, and then added some packages you see where it installed the packages.
And then if I look at my references list you'll see there's a new item here. There's a reference to AutoMapper, there's also one for system, and one for Microsoft CSharp So it's made some changes to my project. Now I'll add a package to TinyWeb I'll right-click and choose manage NuGet packages, before I do that lets go back and look, you'll see if I go to my TinyDesktop and look here in the install section you see AutoMapper is installed there. Now go to TinyWeb and manage NuGet packages you'll see that in the installed section there's nothing there, that's because I installed AutoMapper in TinyDesktop, I did not install it in TinyWeb.
This time I'll choose Bootstrap. When you look at the package in the browse section you get some information here. It's had 4.25 million downloads this I'm looking at version 3.3.6 and on the right side of the screen I can read more information. There's a description a bunch of metadata over here. There's a description, I can see the version number for the latest stable version. I can also read the author name Bootstrap is created by Twitter there are links to the license document. Information about the publishing date and a link to the project site where I can learn more about this package.
Finally, at the very bottom is the dependency information. Bootstrap depends on jQuery the version must be greater than or equal to 1.9.1 and less than or equal to 3.0.0 since I don't have jQuery installed NuGet will handle that for me. Keep your eye on the TinyWeb item in the solution explorer I'll scroll up and click on the install button. Once again I get some information messages here and in the output window and then in TinyWeb I can see there's some changes. There's a new scripts folder here and in the scripts folder I can see there are some jQuery files and there's also some Bootstrap files here.
Boostrap also has some fonts that are available in this fonts folder, and there's some CSS and other content information inside this folder. Now I'll add entity framework to the Asp.net project but before I do that I'll open this web config file so that you can see what happens to it during the install. See that the web config currently has 21 lines of XML I'll right-click on TinyAsp this time you see that I do have some installed items remember I said that this was created using the Asp.net standard templates? So even though I picked an empty Asp.net project there are two available NuGet packages that were created as part of the template.
They're listed here. But I'm not interested too much in that at the moment. I want to look at browse,and I want to find entity framework Here it is, 16 million downloads. I'll click on install. This time there's a license agreement I have to agree to before I can install the package. I'll click I accept And two things happen here. In the solution explorer, you saw some folders appear and disappear, that's the reference folder. And also Visual Studios is telling me that something changed.
Something in the web config changed. So I'm going to reload the modified files and let's look at these two changes oh and the references folder there's now a reference to entity framework and EntityFramework.sqlserver and in web config, there are now 31 lines of XML in there and you can see there's some items in there for entity framework in this section. What that shows is that NuGet can modify some files in your project. At this point, I've added a NuGet package to each project. Next up I'll look at how to manage projects for all the projects in a solution at the same time.
- What is a package manager?
- Installing NuGet in Visual Studio
- Installing and managing packages
- Updating packages
- Working with PowerShell and NuGet
- Finding packages with NuGet Gallery and ASP.NET MVC
- Using Package Restore
- Using the Chocolatey machine packet manager
- Using Boxstarter for creating installation packages
- Using OneGet/PackageManagement
- Creating, publishing, and installing a custom NuGet package