How to create and run ASP.NET CORE MVC project with and without Entity Framework in Visual Studio Code?

Prerequisites (For both with EF and without EF)

1) .NET Core SDK

If you have already installed .NET Core SDK then check whether SDK installed .(as shown below)

image.png

2) Visual Studio Code

3) C# extension for Visual Studio Code. (shown below)

image.png

How to create ASP .NET Core MVC Application without Entity Framework in VS Code?

1) Open VS code and open terminal. Now change the directory or file path where you want to create your application.(shown below)

image.png

2) To create MVC file, type (shown below)

dotnet new MVC

image.png

3) Check whether the command executed successfully and MVC created on the given folder. (as shown below)

image.png

image.png

If any warning message is shown (Required assets to build and debug are missing from ‘projectname’. Add them?) then select Yes.

4) Open the folder in VS Code. File > Open Folder > Select Folder (MVCProjFile).

image.png

5) We can create/edit/delete the files.

image.png

How to create ASP .NET Core MVC Application with Entity Framework in VS Code?

Follow the above steps to create ASP .NET Core MVC application and add EF.

1) Open terminal in VS Code and type

dotnet add package Microsoft.EntityFrameworkCore

image.png

It will automatically add entity framework in .csproj file (shown below)

image.png

How to run ASP .NET Core application in Visual Studio Code?

To run ASP .NET Core application with and without Entity framework.

Way 1:

  1. Go to Run > Run Without Debugging.

image.png

image.png

image.png

image.png

image.png

Way 2:

  1. Type
    dotnet run
    

image.png

We have to click the listening port link(Now listening on:https:// localhost: 5001) as shown in the above snippet. Then it will open the browser and shows the output.

image.png

Success!!!