>> Hi friends. Welcome back to the NuGet 101 series.
I'm Chris, and today we're going to learn how to install
and use a NuGet package with Visual Studio.
To follow along, you will need Visual Studio installed.
To grab the latest version,
check out the links in the description.
Otherwise, let's dive right in.
So I've fired up Visual Studio and you'll see
that I already have a sample project set up.
Where all I'm doing is printing a few examples of
timespans in milliseconds to the console.
Now, milliseconds are commonly used
in software because they're very
easy for computers to understand and they're
very straightforward to do operations with.
Now what's not so easy or straightforward is for
people to understand what large numbers of milliseconds mean.
I have no idea what these numbers are in weeks, days, or hours.
So my goal for this tutorial is going to be to convert
these unintelligible timespans and
milliseconds to a much more
human readable, human understandable form.
Now, I could spend some time developing
a solution to do this from scratch,
or because I did some online research and I
asked a bunch of my really smart developer friends.
There's a.NET package called humanizer
that could help me do this really quickly with minimal added code.
So now I want to try to find this humanizer package.
Fortunately, there's a NuGet package manager
built right into Visual Studio.
So I can open that up by either right-clicking on
my project and going to "Manage NuGet Packages",
or by going to the "Project" tab up
top and going to ''Manage NuGet Packages'' there.
Now, you want to make sure you're in
the ''Browse'' tab so that we can search for packages,
and I'm going to search for the exact name of what I want.
So I'm going to search humanizer.
You'll see that we get a bunch of different results.
That's because there's a bunch of versions
of this package in different languages.
But for this tutorial, I'm just going to get the general one.
Now I feel like I can trust this package because it has
a bunch of downloads as a little verified blue checkmark,
and it says it's good for manipulating and displaying timespans.
I can also see that it has an MIT license,
which is a very permissive license,
so that means I can use it in my project.
Now, this package looks really interesting to me,
but I want to learn a little bit more
about it and I want to learn how to use it.
To do that, I can go to the project
URL and check out the documentation.
So just from first glance,
it looks like humanizer can do a whole bunch of things.
It can humanize strings,
it can transform strings,
it can humanize date times, and humanize timespan.
So pretty quickly I already found what I want.
I can see that it can turn
millisecond timespans into
a much more human-readable human understandable form.
I can conceptualize weeks, days, and hours.
So I'm going to copy this little function from
the library so I can use it a little bit later in my project,
and then go back to Visual Studio.
Since it looks like this is exactly the package I need,
I'm going to go ahead and install it. Hit "Enter".
Then once it's finished installing,
I'll be able to find it on my ''Installed'' tab.
If there were any updates released for it,
I'd be able to find it on my ''Updates'' tab.
So I could move to the newest version.
You'll also find any packages you have installed on
your project and the dependencies under packages.
So now that we've explored
the NuGet Package Manager in
Visual Studio and we've installed the package,
let's try to figure out how we can use it in our code.
So the first thing we always want to do is add
a using statement to the top,
which basically just tells the system, ''Hey,
I want to use the functions from
this library in this code right here.''
Now I can paste in
the commands that we saw from the documentation,
and before I finish doing that,
I want to show you something really neat real quick.
So if I type in.h,
you'll see that Visual Studio surfaces
a bunch of relevant functions for this datatype.
But one of them, the humanized function
has a little downwards arrow next to it.
That means it's coming from an installed library.
So Visual Studio will also surface
relevant functions from installed libraries.
So that's pretty neat.
So I'm just going to finish that off,
and now we have officially installed the package.
We've implemented it into our code,
so let's run the program and see if
everything is going to turn out the way that we expect it to.
All right. So it looks like we have officially converted,
so I can hear you can see them side-by-side,
we've officially converted these unintelligible numbers of
milliseconds and to something as simple as weeks, days, and hours.
Now, that's something I am pretty sure anyone can understand.
So to recap, we learned how to open up the package manager
built into Visual Studio and use it to find packages that we need,
learn more about them,
and then install them into our projects,
and we also learned how we can use
installed libraries in our code with a using statement.
In the next video,
we'll cover how we can install and
use NuGet packages with a.NET CLI.
So until then, thank you so much for watching,
and I'll see you next time.