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
Dependencies of a project are managed using the Reference Manager in 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
We want our project to be able to
extract data from JSON files and
0:01
insert it into a database.
0:04
JSON is a file format that makes it easy
to store structured data in a text file.
0:07
If you haven't seen JSON data yet,
check the teacher's notes for
0:11
some helpful links about it.
0:14
JSON stands for
JavaScript Object Notation and
0:16
it's just a helpful way to store
information in a structured manner.
0:20
We'll need some code that can
systematically read the data from
0:24
these files.
0:27
Now before we write a single line of code,
0:28
we should always ask ourselves has some
of this code already been written.
0:30
If it even remotely seems like someone
else might have done something similar to
0:35
what we want to do, we should always check
first before we spend hours or days or
0:39
weeks reinventing the wheel.
0:44
When working with .NET the first place
we should check is the .NET framework.
0:46
To add an assembly reference to our
project, right-click on References and
0:51
click Add Reference.
0:55
This opens the Reference Manager Window,
on the left side of the window,
0:57
we see an item named Assemblies.
1:02
Under Assemblies there's
the Framework category.
1:05
These are all of the assemblies that come
pre-installed with the version of .NET
1:08
displayed up here.
1:12
In our case it's .NET 4.6.1
because that's the version of .NET
1:14
we told Visual Studio we wanted to
use when we created this project.
1:19
As you can see,
it's really not that long of a list.
1:23
To add an assembly reference,
we can search for it here.
1:28
Let's say we want to add
a reference to System.Net.Http.
1:32
Clicking this checkbox
here means we want to add
1:39
it to the list of assemblies
that our project references.
1:42
When we click OK, a reference to the
System.Net.Http assembly will be added.
1:45
This only searches the names of
the assemblies, not what's inside of them.
1:52
For example, we want a library
that can help us read JSON files.
1:56
One might suspect that such a library
would have JSON in its name.
2:00
So let's type JSON here.
2:04
It says, No items found.
2:07
The Reference Manager isn't the best way
to see what the .NET framework provides.
2:09
For that,
we'll want to look into other resources.
2:13
If we find an assembly from the .NET
framework that does what we want, we can
2:16
come back here to the Reference Manager
and add a reference to it in our project.
2:20
Before we close this window,
2:25
let's take a look at the other
categories in the Reference Manager.
2:26
Extensions are assemblies that came with
Visual Studio or were installed later.
2:30
They aren't part of the .NET framework but
2:35
we can add them as
references to our project.
2:38
They'll be copied into the bin
directory when the project is built.
2:41
The search we just did actually
searches both the Framework and
2:44
Extension categories.
2:48
Projects contains a list of all
the other projects in our solution.
2:50
Real world applications are often
composed of many projects that
2:54
each create an assembly.
2:58
If we had another project in our solution,
3:00
we could have the assembly it creates be
a dependency of our JSON to DB project.
3:02
Right now our solution only
contains the JSON to DB project.
3:08
So this list is empty.
3:12
Shared projects is a relatively
new feature in Visual Studio.
3:14
A shared project is a special type of
Visual Studio project that can't be used
3:18
to create its own assembly.
3:22
They represent a collection of files that
can be combined with other projects.
3:24
If we had a shared
project in our solution,
3:29
we could add a reference
to it from JSON to DV.
3:32
When we built the solution,
all of the files in the shared project
3:35
would be compiled into the JSON to DB
application as a single executable file.
3:39
COM are libraries that are used
to communicate directly with
3:44
other programs that run
on Windows computers.
3:47
These are not part of the .NET framework
and like the framework extensions,
3:50
they also came with Visual Studio or
were installed later.
3:54
If the assembly we need is sitting
on our computer somewhere,
3:58
we can click Browse to find it.
4:01
This opens the open file
dialog that we can use to
4:05
find the assembly that we
want to add to our project.
4:08
After clicking OK we can see
that we now have a reference to
4:11
the System.Net.Http
assembly in our references.
4:15
We still don't know which library to
use to help us read JSON files or
4:20
even if this is something that
the .NET framework provides already.
4:23
I think it's time to turn to Google.
4:27
Let's search for .NET Read JSON.
4:29
There are many libraries that
can be used to read JSON.
4:36
The neat thing about search engines
is the search results are usually
4:40
ordered by how popular the libraries are.
4:43
When it comes to libraries,
being popular is good.
4:46
It means there are lots of
other developers using it.
4:49
It probably has pretty good documentation,
most of the bugs have been worked out, and
4:52
it's likely to be around for a while.
4:57
That is, until another library
becomes more popular than it.
5:00
If in doubt, do more research.
5:03
Which libraries to use is
a common topic on forums and
5:05
QA sites like stackoverflow.com.
5:09
In the end it almost always comes down to
picking the library that looks the most
5:11
promising and trying it out ourselves.
5:16
Now just because it's the top
search result in Google,
5:18
doesn't mean it's going to be the best
library for what we want to do.
5:21
After looking around,
we discover that this
5:25
JSON.NET library from Newtonsoft
is exactly what we want.
5:29
Now we could go to the Newtonsoft
website and browse around and
5:34
try to figure out how to download the
library, then download it to our computer,
5:37
then browse to it in
the reference manager and add it.
5:41
But there's a better way.
5:45
This is what NuGet is all about.
5:46
In the next video, let's see how we can
use NuGet to fetch this library for us.
5:49
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