Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
There are a few options to consider when installing packages and their dependencies.
-
0:00
We now have all the dependencies our JsonToDb program needs to do its job.
-
0:05
Now we need to do is use these libraries in our code and write the program.
-
0:09
Because this workshop is about package management with NuGet,
-
0:12
we'll leave that task for another day.
-
0:14
To play with some more features of NuGet, let's create a whole new project.
-
0:18
This time we'll create a project for an ASP.NET MVC application.
-
0:23
So we'll click File > New > Project.
-
0:27
Under Web, click ASP.Net Web Application.
-
0:31
For this demo, just leave the project name and location the same, and click OK.
-
0:38
We'll create an MVC web application and uncheck this box to host in the cloud.
-
0:43
Pay attention to what happens when I click OK here.
-
0:47
Because this is the first time I've created an ASP.NET MVC application on this
-
0:51
computer, it will take a bit longer than usual to create this project.
-
0:56
The reason for this is because most of the libraries that are needed to
-
0:59
create an MVC application are downloaded from NuGet.
-
1:03
when we look at our project,
-
1:04
we can see that there's already a packages.config file.
-
1:08
If we open the file, we can see a list of all the NuGet packages that our
-
1:12
project needs, and we have a lot of assemblies listed under References.
-
1:17
These were all installed from NuGet when the project was created.
-
1:22
Let's add another package to our project.
-
1:25
ELMAH is a popular way to add error logging to a website.
-
1:29
It makes it much easier to troubleshoot errors that happen
-
1:31
in ASP.NET applications.
-
1:34
Since we only have a single project in our solution, just right-click
-
1:37
on the project name to manage the NuGet packages for this project.
-
1:41
In the search bar under Browse, we'll type elmah.
-
1:46
Since we're creating an ASP.NET MVC application, we'll select Elmah.MVC.
-
1:53
Look over here in the details.
-
1:54
Notice that this package has a dependency on the ELMAH core library package.
-
2:00
Nuget packages can have dependencies on other Nuget packages.
-
2:03
By installing Elmah.MVC, it will install elmah.corelibrary for us automatically.
-
2:10
So NuGet not only manages the dependencies of our project, but
-
2:14
also the dependencies of those dependencies, and so forth.
-
2:17
Here it says that Elmah.MVC will work with
-
2:22
version 1.2.0 or greater of elmah.corelibrary.
-
2:26
Let's go back up here and expand the Options area.
-
2:30
These options don't only apply to the Elmah.MVC package we've selected.
-
2:35
Changing these options will change them for
-
2:37
all future packages we want to install.
-
2:40
But we can change these options each time we want to install, update, or
-
2:44
uninstall a package.
-
2:45
Just be aware that they will remain set that way for
-
2:48
the next package you want to install unless you change them again.
-
2:52
Here we have a few options for how to deal with dependencies.
-
2:55
Inside the Dependency behavior drop-down we see an option for Ignore Dependencies.
-
3:01
If this is selected,
-
3:03
then none of the dependencies of our packages will be installed automatically.
-
3:06
These other options allow us to control which version of the dependencies
-
3:10
should be used.
-
3:11
NuGet assumes that all packages are versioned using
-
3:14
the Semantic Versioning schema.
-
3:16
Semantic Versioning refers to three numbers separated by dots.
-
3:20
It's pretty straightforward.
-
3:21
The three numbers correspond to the major, minor, and patch version numbers.
-
3:25
[SOUND] When versioning the library, we should increment the major version number
-
3:30
when we make breaking changes to the API, meaning code that worked with the previous
-
3:34
version might need to be changed in order for it to work with the new version.
-
3:39
We should increment the minor version when we add new features to the library
-
3:42
that won't break any code that uses the library.
-
3:46
And we should increment the patch version when releasing a version that
-
3:49
only contains bug fixes.
-
3:51
Finally we can identify prerelease versions of the library
-
3:55
by appending -alpha, -beta and so on to the end of the version number.
-
4:01
When searching for NuGet libraries, we can see packages that are only in prerelease
-
4:05
by checking this check box here.
-
4:07
This is handy when we want to experiment with future versions of a library.
-
4:11
With Semantic Versioning in mind, the rest of these options start to make sense.
-
4:17
Lowest refers to the lowest version that can be used.
-
4:20
In the case of elmah.corelibrary, this is 1.2.0 because that's
-
4:25
the lowest version that Elmah.MVC says it can work with.
-
4:32
Highest Patch refers to the lowest minor version, but highest patch version.
-
4:37
In the case of elmah.corelibrary, the lowest minor version is 1.2.
-
4:42
But it should get the highest patch of 1.2 available.
-
4:46
Highest Minor would get the highest minor and
-
4:48
patch version for elmar.corelibrary that has a major version of 1.
-
4:53
Highest gets the latest and greatest non-prerelease version of the library.
-
4:57
By default, NuGet comes preconfigured to always install the lowest version of
-
5:01
the dependency.
-
5:03
However it's usually best to use the latest version of the library possible
-
5:07
because it probably contains the fewest bugs and
-
5:10
we can use it longer without it becoming too far out of date.
-
5:13
You might think that NuGet should always install the highest version that's
-
5:16
guaranteed to work with the library that depends on it.
-
5:19
In that case, we would always want the highest minor version.
-
5:23
The reason NuGet doesn't select this by default is because not all libraries
-
5:27
are versioned using Semantic Versioning.
-
5:30
They may use their own versioning system where a minor version may contain breaking
-
5:34
changes.
-
5:34
elmah.corelibrary uses Semantic Versioning, so
-
5:37
I'm going to pick Highest Minor.
-
5:40
This means we'll get a later version of elmah.corelibrary then we would have
-
5:45
had we left this at Lowest.
-
5:48
I mentioned earlier that NuGet packages have the ability to add files to a project
-
5:52
other than just libraries.
-
5:54
The File conflict action option here tells NuGet what to do if the file it's
-
5:58
trying to add already exists in the project.
-
6:01
We can also tell NuGet what to do when a package is uninstalled from a project.
-
6:06
By checking this box, we tell NuGet to uninstall any dependencies
-
6:09
that were installed with the package when this package is uninstalled.
-
6:13
The second checkbox, Force uninstall,
-
6:16
has to do with uninstalling packages that are dependencies of other packages.
-
6:21
By checking this box, NuGet can uninstall a package even if there is another package
-
6:26
in the project that depends on it.
-
6:28
In most cases we want to keep Remove dependencies checked and
-
6:33
Force uninstall unchecked.
-
6:36
Let's click the Install button to install Elmah.MVC.
-
6:42
Now this preview makes even more sense.
-
6:45
We can review here the versions of the packages that will get installed.
-
6:49
We can see here that instead of installing version 1.2.0 of elmah.corelibrary,
-
6:55
we're getting 1.2.2 instead because we chose to install the highest minor and
-
7:00
patch versions available.
You need to sign up for Treehouse in order to download course files.
Sign up