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