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
What are the true dependencies of a .NET project?
This video doesn't have any notes.
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
NuGet manages the packages of
an entire solution or project.
0:00
So let's create ourselves
a project to add dependencies to.
0:04
Click File New Project.
0:07
Let's make sure we're using
the latest version of .net here.
0:12
Let's start by creating
a console application.
0:16
So in the templates, under Visual C# >
Windows, click on Console Application.
0:19
This console app will take the data from
JSON files and store it in a database.
0:25
So, let's call it JsonToDb.
0:29
We'll just create it in
the default directory right here.
0:34
Now we have a basic console app
project that we can start coding in.
0:39
Let's take a look at which assemblies
our program depends on so far.
0:44
We can do that by looking under
references in the Solution Explorer.
0:49
Each of these references
represents a single .NET
0:53
assembly that our application
might need in order to run.
0:56
Let's take a look at one of them.
1:00
Click on one of them, and
1:02
details about the assembly will
appear in the Properties window.
1:04
If you don't have the Properties window,
you can right-click on the assembly and
1:08
click Properties.
1:12
Scroll down and
take a look at the Path property.
1:14
This dll file extension here stands for
dynamically linked library.
1:17
So, this is where the actual library
file resides on the computer.
1:21
Remember in dot net we call
these DDLs assemblies.
1:26
Look a little further
down to runtime version,
1:29
this assembly will work with this
version of dot net or later.
1:32
A computer can have multiple
versions of dot net installed on it.
1:35
Look a little further down
at the version property.
1:40
This is the actual version number
of this specific assembly.
1:44
Looking back at this list of references,
this seems like a lot of dependencies for
1:48
an app that doesn't do anything yet.
1:52
It turns out that our app
as it's written right now
1:55
doesn't actually need any of these.
1:57
Visual Studio added these references when
it created the project from the console
2:00
application template, because
they're a commonly used assemblies.
2:04
It added them automatically
because it suspects that some
2:08
time in the future we'll want them.
2:11
Having them here doesn't hurt anything,
2:13
because all the assemblies
here are already part of
2:15
the .Net framework that's installed
on every Windows computer.
2:18
So it's not like having these dependencies
is going to increase the size of our app
2:21
to demonstrate this.
2:26
Let's go ahead and build this app.
2:27
First, let's change the build
configuration to release so
2:30
that we can make sure that it's
only building what's needed to
2:34
run this program on another computer.
2:37
Let's click build and then build solution.
2:39
See here that we can type Ctrl+Shift+B on
the keyboard instead, the project build.
2:43
Now let's take a look at
the project's bin directory.
2:50
I right clicking on the project's name and
clicking Open Folder in File Explorer.
2:53
When Visual Studio builds
a Windows application,
2:58
it copies all of the files that are needed
to run the program into the bin directory.
3:00
Take a look inside the bin directory,
and then go inside the Release folder.
3:05
All these vshost and
PDB files are only used by Visual Studio.
3:11
The exe.config file allows us to change
the runtime configuration of the program.
3:16
Technically, JsonToDb.exe is
the only file we really need.
3:22
Notice that all of those other DLLs that
were listed in references aren't here.
3:28
We just expect that they'll
be on the users' computers
3:32
as part of the .NET Framework.
3:35
Most developers just leave
these references here
3:37
a fun way to explore these assemblies is
to look at the object browser window.
3:40
We can open it by clicking on view and
3:45
Object Browser over here on
the left side of the window.
3:48
We see a list of all the assemblies
that are application is using so far.
3:52
We can explore around them
by clicking this triangle.
3:56
Now we can see all of the types that this
assembly provides organized by name space.
4:00
To see what our program really needs
in order to run, we can remove
4:06
all of the references over here by
selecting them all, right clicking and
4:10
clicking remove, then confirm that we
really want to remove these items.
4:15
Removing these assemblies from
references just tells Visual Studio
4:21
that they shouldn't be considered
dependencies of our application anymore.
4:25
I'll build the solution by typing
control+Shift+B to show that the project
4:29
builds just fine without these references.
4:32
See here in the output window shows
that everything built successfully,
4:35
notice that in the Object Browser
there are still a few items.
4:39
Json to DB is our executable
assembly MSCoreLib and
4:43
system.core are the core
of the .Net Framework.
4:48
Every .Net project at a minimum has
a dependency on these two assemblies.
4:52
Even though they aren't listed in
the references of the project,
4:57
they're considered implicit
dependencies of our project.
5:00
I encourage you to explore around
these assemblies a bit to see
5:03
what these provide you.
5:07
You'll see that you can do a lot
with just what's in MS core lib,
5:08
even with everything that done it
provides right out of the box, inevitably
5:13
you want to leverage some libraries
that don't come pre-installed with .Net.
5:17
That's where NuGet comes in our project
5:21
is about as simple as a project
in visual studio can be.
5:24
In the next video let's
start adding to it.
5:28
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