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

YESHWANTHINI S
Techiepedia
Published in
3 min readApr 22, 2021

How to develop ASP.NET Core MVC application with and without Entity Framework using VS code? Let’s see

Credit: Google Images

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 in figure 1)

Figure 1

2. Visual Studio Code

3. C# extension for Visual Studio Code. (shown in figure 2)

Figure 2

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 in figure 3).
Figure 3: Changed directory and created folder (MVCProjFile).

2. To create MVC file, type dotnet new MVC.

when executing that command, your sdk version will be displayed then project gets created.
ASP.NET Core application gets created on the given folder(MVCProjFile).
Successfully created!!

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

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

MVCProjFile file structure.
HomeController.cs file.

We can create new controller, view and model files also. In VS code, it is easy to create files than Visual Studio Community.

New file creation from controller.

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.
  2. Type dotnet add package Microsoft.EntityFrameworkCore
Adding EF in existing project.

It will automatically add entity framework in .csproj file (as shown in figure 4)

Figure 4

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. Run > Run Without Debugging.
Run the project.
Start , Stop and Restart option.
Project build successfully.
Debug console showing port details.
Success!!

Way 2:

  1. Type dotnet run in terminal.
Build and debug details are displayed.

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.

Success!!!!

--

--