Add external packages

    NuGet is both the package manager tool and the official package repository (at ). You can search for NuGet packages on the web, and install them from your local machine through the terminal (or the GUI, if you’re using Visual Studio).

    At the end of the last chapter, the to-do application displayed to-do items like this:

    The due date column is displaying dates in a format that’s good for machines (called ISO 8601), but clunky for humans. Wouldn’t it be nicer if it simply read “X days from now”? You could write code that converted a date into a human-friendly string, but fortunately, there’s a faster way.

    To add it to your project, run this command in the terminal:

    If you peek at the project file, you’ll see a new PackageReference line that references Humanizer.

    Use Humanizer in the view

    To use a package in your code, you usually need to add a statement that imports the package at the top of the file.

    Since Humanizer will be used to rewrite dates rendered in the view, you can use it directly in the view itself. First, add a @using statement at the top of the view:

    Then, update the line that writes the property to use Humanizer’s Humanize method:

    Now the dates are much more readable:

    Human-readable dates

    There are packages available on NuGet for everything from parsing XML to machine learning to posting to Twitter. ASP.NET Core itself, under the hood, is nothing more than a collection of NuGet packages that are added to your project.

    In the next chapter, you’ll use another set of NuGet packages (a system called Entity Framework Core) to write code that interacts with a database.