Installing the ASP.NET Core NuGet Package in Your Application

We'll straight away jump to installing the ASP.NET Core NuGet package in your application.

Follow these steps to install the NuGet package of ASP.NET MVC:

  1. Right-click on the dependencies, and select the Manage NuGet Packages option:

  1. We will see that a package called Microsoft.ASPNetCore.All is installed (as shown in the following screenshot). This package is actually a meta package that installs most of the dependencies we need.

  1. If we extend this package from dependencies, we will see:

So, everything we need is already installed regardless of using an empty project or not.

ASP.NET Core is installed in our application. Now, we need to tell our application to use ASP.NET MVC.

This needs a couple of changes to the Startup.cs file:

  1. Configure the application to add the MVC service. This can be done by adding the following line to the ConfigureServices method of the Startup class:

Go to https://goo.gl/RPXUaw to access the code.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
  1. Configure the routing so that our correct controllers will be picked for the incoming requests based on the URL entered. The following code snippet needs to be updated in the Configure method of the Startup.cs file:

Go to https://goo.gl/Xa1YcD to access the code.
public void Configure(IApplicationBuilder app,IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}
/{action=Index}/{id?}");
});
}

In the preceding statement, we are configuring the routes for our application.

In this chapter, and most of the chapters in this course, we will write codes manually or choose an Empty template instead of relying on scaffolding templates. For those who are new to the term scaffolding, scaffolding is a feature that generates all the necessary boilerplate code for you for the selected item (for example, the controller) instead of you needing to write everything.

Though scaffolding templates are useful and save time in generating the boilerplate code, they hide many of the details that beginners have to understand. Once you write code manually, you'll know all the intricacies of how each of the components is contributing to the big picture. Once you are strong in the fundamentals, you can use scaffolding templates to save you time in writing the boilerplate code. Scaffolding is also useful for creating quick administrative pages to edit our database.