This workshop will be retired on May 1, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
How to find and install NuGet packages using Visual Studio.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
To use NuGet,
we go to this Solution Explorer, and
0:00
right click on References in the project,
and click Manage NuGet Packages.
0:02
NuGet opens up as a tab
in the main workspace.
0:08
Up here we have Browse,
Installed, and Updates.
0:12
Under Browse a list of
the most popular and
0:16
recently downloaded packages is displayed.
0:19
Now right away we see this
Newtonsoft.Json in the list.
0:22
Let's ignore that for right now.
0:26
If we want to see all of the packages
that had the word Json in their name or
0:28
description, we can type Json
here in the search field.
0:31
The result shown are ordered
by relevance and popularity.
0:36
We can see that Newtonsoft.Json
is at the top of the list.
0:39
But there are other packages that also
seem to have something to do with
0:43
working with JSON.
0:47
Maybe one of these packages
would better suit us.
0:48
We can get more information
about the selected package
0:51
by looking over here on the right side.
0:54
This shows us details about the package.
0:56
We see a description of the package,
the latest version number,
0:59
a link to information about its license,
and
1:02
a link to the web page that can
tell us more about the package.
1:05
There isn't a lot of information here,
but we can click on this link or
1:08
search the web for more information.
1:12
We can tell that this Newtonsoft.json
package is by far the most popular.
1:14
So we'll go with that for now.
1:20
Over here beside the install button,
there's a dropdown that allows us to
1:22
select which version of
the package we want to install.
1:25
in most cases, the package version number
1:29
matches the version number of
the library that it contains.
1:31
The latest stable version of the package
that will work with the version
1:35
of .NET that our project
targets is selected by default.
1:38
We can opt to download a previous
version if we want though.
1:41
And there are times we might want to
do that, which we'll talk about later.
1:45
For now, let's install the latest
version by clicking Install.
1:48
We'll see a confirmation dialog pop up
that confirms with us that we want to
1:52
install the package into our solution and
add it to the JsonToDb project.
1:56
After clicking Yes,
check out the output window down here.
2:01
If we look up here,
2:05
we can see that it opened a new tab
with a readme file about this library.
2:05
The readme file contains more
information that we might want to
2:11
know about the library.
2:14
We'll close this for right now.
2:16
We can see that it added a check
mark to the package, and
2:18
if we click on the Install tab we see
it listed as an installed package.
2:22
In the Solution Explorer we
can see what else happened.
2:27
We can see that
the Newtonsoft.Json assembly,
2:31
is now listed as one of our references.
2:34
Because this is the first NuGet
package that was added to the project,
2:37
we now have a new file in
the project named packages.config.
2:41
Let's take a look at that file.
2:46
It's an XML file that lists the NuGet
packages that our project depends on.
2:47
Notice that it not only says which version
of the package our project needs but
2:52
also which version of .NET we're
targeting when we downloaded the file.
2:57
In order to write to the database,
we'll also need Entity Framework.
3:02
\Entity framework is a framework for
mapping objects and
3:05
code to objects such as
tables in a database.
3:09
Although Entity Framework
is Microsoft product.
3:12
It's not part of the .NET Framework.
3:15
So we'll need to add it using NuGet.
3:17
The list of packages that's displayed
here is called the NuGet Package Gallery.
3:19
And as you can see, Entity Framework
is also a commonly downloaded package.
3:24
Let's select it and
click Install to add it to our project.
3:30
We see the confirmation dialog,
and next we see another dialog for
3:35
us to either accept or
decline the license.
3:40
Software and libraries that
are distributed to the public
3:43
often have a license that dictates how
the software can and cannot be used.
3:46
It's always up to the user of the software
to make sure that they're using it in
3:51
compliance with its license.
3:55
Sometimes the licenses
are very permissive.
3:57
The most permissive licenses simply
say that the manufacturer or
4:00
distributor of the software
is not liable for
4:03
anything bad that might happen as
a result of using the software.
4:06
Often times, licenses state if and
how the software can be redistributed.
4:09
Many licenses state the circumstances
under which you may allow other people
4:15
other than yourself to use the software or
library.
4:19
Just because code is open source doesn't
mean we can do whatever we want with it.
4:23
For example, some open source libraries
have fairly restrictive licenses which
4:28
state that if you want to use
the library in your own application.
4:32
You also have to make all of the source
code of your application available to
4:36
the public for free.
4:40
Unless that is,
4:41
you have express permission from
the originator of the library.
4:42
It doesn't matter if you're using it for
commercial purposes or not.
4:46
I can't give you more legal
advice than this, but
4:49
I can say that it's important to respect
the terms of all software licenses.
4:52
And don't assume that a library can be
used in the way you expect it should be
4:57
able to be used.
5:01
For more information about
the various software licenses you
5:02
might find out there, check
the teacher's notes of this workshop.
5:05
You can read the license for
Entity Framework.
5:09
After reading the license, I know I'm
well within the terms to download it and
5:11
use it for what we want to do today.
5:14
So I'm going to click I Accept.
5:16
If you want to go back and
read the license for
5:19
any package, you can usually find a link
to it in the package details in NuGet.
5:20
If you see this dialog pop up,
5:25
it just means that you have
the packages.config file open.
5:27
It's asking if it can save
changes to an open file.
5:31
We'll say Yes to All.
5:35
We don't need this file open,
so I'll close it now.
5:38
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up