Setting Up an ASP.NET Core Project
Create your first ASP.NET Core web application and understand the generated project structure.
C# & .NET learning pathLesson 48 of 66
View course On this page 6 sections
Creating a New Project
dotnet new webapi -o TaskApicd TaskApiThis scaffolds a minimal Web API project — a great starting point for the projects you'll build throughout this section.
Project Structure
| File/Folder | Purpose |
|---|---|
| Program.cs | Application entry point and configuration |
| appsettings.json | Configuration values (connection strings, settings) |
| Controllers/ | API controllers (added as you build) |
| *.csproj | Project file listing dependencies and settings |
Understanding Program.cs
Program.cs
var builder = WebApplication.CreateBuilder(args);
// Add services to the containerbuilder.Services.AddControllers();
var app = builder.Build();
// Configure the HTTP request pipelineapp.UseHttpsRedirection();app.MapControllers();
app.Run();This single file both configures services (dependency injection, covered later) and builds the middleware pipeline that handles every incoming request.
Running the App
dotnet runExample Output
Click Run to see what this code prints.
FAQs
webapi scaffolds a JSON API with no views; mvc adds Razor views and a full web app structure — you'll use both patterns in this section.
Summary
dotnet new webapiscaffolds a new ASP.NET Core Web API project.- Program.cs configures services and the request pipeline in one place.
dotnet runstarts the app and prints the URL it's listening on.