ASP.NET Core · VS Code · Beginner to advanced

Run ASP.NET Core in VS Code — From Zero to Infinity

Begin with one command, then gradually master coding, running, debugging and deployment.

00 · Understand the tools

VS Code is the editor. C# is the language. .NET SDK provides build/run commands. ASP.NET Core runs your web application using the Kestrel server. Your browser opens the URL shown in the terminal.

Visual Studio Code and Visual Studio are different products. This guide uses VS Code on Windows, macOS or Linux.

01 · Install everything

  1. Download Visual Studio Code.
  2. Download a supported .NET SDK (not runtime only).
  3. Open Extensions in VS Code (Ctrl+Shift+X) and install Microsoft's C# Dev Kit (with its dependencies).
  4. Open a new integrated terminal: Terminal → New Terminal.
dotnet --info
dotnet --list-sdks
dotnet new list web

If dotnet is not recognized, restart VS Code and check the SDK installation and PATH.

02 · Your first website in VS Code

Create a folder and open it in VS Code:

dotnet new web -n HelloPicnic
cd HelloPicnic
code .

In Program.cs, write:

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "Hello from VS Code and ASP.NET Core!");
app.MapGet("/hello/{name}", (string name) => $"Hello, {name}!");

app.Run();

Start the server:

dotnet run

Open the exact Now listening on URL printed in the terminal. Add /hello/Asha to that URL and try it. Stop using Ctrl+C.

03 · Understand the project structure

File/folderRole
Program.csCreates the web app and maps endpoints
HelloPicnic.csprojProject configuration and target framework
appsettings.jsonGeneral configuration
Properties/launchSettings.jsonOptional local launch profiles and ports
bin/ and obj/Generated build output, not hand-written application code

The web template is different from the webapp Razor Pages template.

04 · Run, build and watch

dotnet restore
dotnet build
dotnet run

dotnet restore retrieves dependencies; build compiles; run starts your app. For development, use:

dotnet watch run

Watch monitors changes and attempts to hot reload or restart the app where appropriate. Stop with Ctrl+C. Avoid running a second server on the same port.

05 · Debug with breakpoints

  1. Open the project folder (not just a single C# file).
  2. Ensure C# Dev Kit has detected the project.
  3. Open Program.cs and click the margin beside a line inside your endpoint to add a breakpoint.
  4. Choose Run and Debug, select a generated .NET launch configuration if prompted, then press F5.
  5. Open the endpoint in your browser. Examine Variables, Watch and Call Stack.
  6. Use F10 to step over, F11 to step into, and Shift+F5 to stop.

If no launch configuration appears, run the command palette's .NET: Generate Assets for Build and Debug when available, or consult the current C# Dev Kit debugging documentation.

06 · Use HTTPS and choose a port

dotnet dev-certs https --trust

Trust the certificate only on your own development machine. The terminal's listening URL is authoritative. To deliberately use port 5055:

dotnet run --urls http://localhost:5055

Then visit http://localhost:5055. A configured launch profile or explicit settings may affect the selected URL; dotnet run --no-launch-profile --urls http://localhost:5055 avoids profile settings for a predictable example.

07 · Create a Razor Pages website

Open a different folder and create a new project:

dotnet new webapp -n PicnicRazor
cd PicnicRazor
code .
dotnet run

Inspect Pages/Index.cshtml for HTML and Razor syntax, Pages/Index.cshtml.cs for the PageModel, Pages/Shared/_Layout.cshtml for the layout and wwwroot for static assets.

Continue with Razor 0 to Infinity.

08 · Create a small Web API

In the original HelloPicnic app, add before app.Run():

app.MapGet("/api/products", () => new[]
{
    new { Id = 1, Name = "Notebook", Price = 40 },
    new { Id = 2, Name = "Pen", Price = 10 }
});

Request /api/products in the browser to see JSON. This is an in-memory example, not a database. Later you can introduce validation, POST, persistence and security.

09 · Diagnose common problems

  • dotnet not recognized: install SDK, restart terminal, check PATH.
  • SDK version mismatch: inspect global.json, .csproj, and dotnet --list-sdks.
  • Port already used: stop the other process or choose another URL.
  • HTTPS certificate warning: trust the development certificate on your own machine; never bypass production TLS security.
  • 404 Not Found: check the mapped path and route method.
  • C# Dev Kit not debugging: open the project folder and wait for project load; check extension output.
  • Site not accessible from another computer: localhost is only your computer; use suitable deployment or controlled network binding for external access.

10 · Publish your application

Publish compiled files:

dotnet publish -c Release -o ./publish

This prepares files for a compatible ASP.NET Core host. Unlike static HTML, server-side ASP.NET Core cannot run directly on GitHub Pages. Deploy to a suitable .NET hosting service, Linux server, container, or Azure App Service. Configure HTTPS, environment variables and secrets appropriately.

11 · Final project and what's next

Mini-project: create a course directory with routes /, /courses, and /api/courses; run it with dotnet watch; set a breakpoint; then publish in Release configuration.

Next: Razor Pages, MVC, dependency injection, EF Core/SQLite, REST validation, authentication, automated tests, Docker and cloud deployments. Master each step before moving forward.

Official sources: ASP.NET Core with VS Code · C# and .NET in VS Code.