How to Build an ASP.NET Core MVC App Using Visual Studio Code
✅ 1. Install Prerequisites
Before we start coding, you’ll need the following tools installed on your system:
- ✅ .NET SDK (Latest LTS version, e.g., 8.0)
- ✅ Visual Studio Code
- ✅ C# Extension for VS Code
➡️ Download Visual Studio Code
To install the C# extension, open VS Code and search for "C#"
in the Extensions sidebar, then click Install.
✅ 2. Create a New ASP.NET Core MVC Project
Open your terminal or command prompt and run the following command:
dotnet new mvc -n HelloWorldMvc
This creates a new ASP.NET Core MVC project in a folder named HelloWorldMvc
.
cd HelloWorldMvc
Now, open it in VS Code:
code .
When prompted, click “Yes” to add build and debug assets.
✅ 3. Run the App
Inside the VS Code terminal, run:
dotnet run
Once the app is running, visit https://localhost:5001
in your browser. You should see the default ASP.NET Core MVC homepage!
✅ 4. Display “Hello World”
🔹 Step 1: Edit the Controller
Open Controllers/HomeController.cs
and replace the Index()
method with:
public IActionResult Index()
{
ViewData["Message"] = "Hello World from ASP.NET Core MVC in VS Code!";
return View();
}
🔹 Step 2: Update the View
Edit the file Views/Home/Index.cshtml
and replace its contents with:
@{
ViewData["Title"] = "Home Page";
}
@ViewData[“Message”]
Now refresh your browser. You’ll see your custom “Hello World” message!
✅ 5. Bonus Tips
- ⚡ Use
dotnet watch run
to auto-refresh on code changes - 🐞 Use breakpoints and the VS Code debugger (press F5)
- 🌐 Customize routing via
Program.cs
orStartup.cs
depending on version
🚀 Summary
With just a few steps, you’ve set up a working ASP.NET Core MVC app in VS Code! This setup is fast, cross-platform, and perfect for developers who want flexibility without the full weight of an IDE.
Happy coding! 🎉