Scaffolding an ASP.NET Core MVC application using dotnet command

We all know that the dotnet new command will create a new console project containing a two files Program.cs and project.json out of the box for you

dotnet new

dotnet new console app

Output

dotnet new console app directory

It was of great help in getting started with a console application in .NET Core, but this command was missing a more important feature – the ability to create a ASP.NET Core Web project from the command line. So, we developers relied on scaffolding tools such as yeoman to generate Web/MVC/Web API projects targeting .NET Core. So whenever the .NET team made changes to the framework and tools, we faced some incompatibilities. Either we needed to wait till the template is upgraded to support the new changes or needed to manually update the files after the project is created.

This is now a thing of the past with the latest update to the .NET Core project implementing to facility to scaffold an MVC project targeting the Core  framework.

Syntax

dotnet new –t web

Output

dotnet new mvc project

dotnet new mvc project directory

The process of building and running the web project remains the same by using the following statements

dotnet restore //restores the referenced packages
dotnet run //compiles the project if it’s not and then hosts the application in the default port 5000

dotnet restore mvc core app

dotnet run web app

web app in browser


No Comments

Add a Comment