skip to content

Starter Templates & SDK

The dotnet new web, webapi, webapiaot, mvc, webapp, blazor and grpc templates, their flags, and the Microsoft.NET.Sdk.Web project they write. Interviewers ask which template fits and what it wires up.

part ofASP.NET Coreread it →
on this pageshow

explore

questions

5

With the .NET 10 SDK, what does dotnet new webapi generate by default, and how do --use-controllers, --no-openapi and --no-https change it?

level: juniorimportance: must knowfreq 72%

answer

  1. Minimal APIs unless told otherwise
  2. -controllers / --use-controllers
  3. AddOpenApi + MapOpenApi, Development only
  4. Microsoft.AspNetCore.OpenApi, no Swashbuckle
  5. --no-https drops UseHttpsRedirection

basics

~20 s

In .NET 10, dotnet new webapi writes a Minimal API project on Microsoft.NET.Sdk.Web: one weather-forecast MapGet, the built-in OpenAPI document mapped in Development, and HTTPS redirection. --use-controllers, --no-openapi and --no-https switch those parts off or over.

solid answer

~30 s

A plain `dotnet new webapi` gives a **Minimal API** project: `Program.cs` calls `WebApplication.CreateBuilder`, `AddOpenApi()`, maps `MapOpenApi()` only when `app.Environment.IsDevelopment()`, calls `UseHttpsRedirection()` and maps one `GET /weatherforecast` endpoint. The `.csproj` uses `Microsoft.NET.Sdk.Web` with `Nullable` and `ImplicitUsings` enabled and references just `Microsoft.AspNetCore.OpenApi`, plus a `.http` file for trying the endpoint. `--use-controllers` (`-controllers`) switches to `AddControllers()`, `UseAuthorization()`, `MapControllers()` and a `WeatherForecastController` with `[ApiController]`. `--no-openapi` removes the OpenAPI package and both calls. `--no-https` removes the https launch profile and `UseHttpsRedirection()`. There is no Swashbuckle, no Swagger UI and no `--aot` flag: Native AOT is the separate `webapiaot` template.

code

bash · 1 line
bash
dotnet new webapi --use-controllers --no-openapi -o ParcelLockers.Api

go deeper

for a junior

Recall that the default is Minimal APIs with one weather-forecast endpoint, that controllers need --use-controllers, and that OpenAPI comes from Microsoft.AspNetCore.OpenApi, not Swashbuckle.

for a middle

Explain each flag's effect on Program.cs and the csproj, why MapOpenApi sits behind IsDevelopment, and why --no-https is ignored for SingleOrg and IndividualB2C.

for a senior

Show you scaffold deliberately: pick controllers or Minimal APIs for the team, decide whether the document ships beyond Development, and know that AOT means the webapiaot template.

for a principal

Treat the template as a team baseline: which defaults you keep across services, where the API contract is published, and how a shared scaffold avoids every repo drifting.

## What the default command writes `dotnet new webapi` is the ASP.NET Core Web API template. In the .NET 10 SDK it describes itself as using "ASP.NET Core controllers or minimal APIs, with optional support for OpenAPI and authentication", and the defaults pick **Minimal APIs**, **OpenAPI on**, **HTTPS on** and **no authentication**. A run of `dotnet new webapi -o ParcelLockers.Api` produces: - `ParcelLockers.Api.csproj` with `Sdk="Microsoft.NET.Sdk.Web"`, `TargetFramework` `net10.0`, `<Nullable>enable</Nullable>` and `<ImplicitUsings>enable</ImplicitUsings>`; - a single `PackageReference` to **`Microsoft.AspNetCore.OpenApi`** — everything else comes from the `Microsoft.AspNetCore.App` shared framework; - `Program.cs` holding the whole app, including a `record WeatherForecast`; - `appsettings.json` and `appsettings.Development.json` with log levels and `AllowedHosts`; - a launch-settings file under `Properties/` for local runs; - `ParcelLockers.Api.http`, a request file that issues `GET /weatherforecast/` against the local port. ## The Program.cs the default writes The generated pipeline is short. The builder registers `builder.Services.AddOpenApi()`, the app maps `app.MapOpenApi()` inside an `if (app.Environment.IsDevelopment())` block, calls `app.UseHttpsRedirection()`, and maps `app.MapGet("/weatherforecast", ...)` with `.WithName("GetWeatherForecast")`. The OpenAPI document is served at `/openapi/v1.json` — `MapOpenApi`'s default pattern is `/openapi/{documentName}.json` and the default document name is `v1` — and because of the `IsDevelopment()` guard it is **not** served in Production. In .NET 10 that document is OpenAPI **3.1** by default. What the template does **not** add matters as much in an interview: - **No Swashbuckle and no UI.** Since .NET 9 the templates use the built-in `Microsoft.AspNetCore.OpenApi` generator; `AddSwaggerGen`, `UseSwagger` and `UseSwaggerUI` come only from the separate Swashbuckle.AspNetCore packages, which you add yourself if you want them. - **No controllers folder** unless you ask for one. - **No authentication** unless `--auth` names a scheme. ## The flags that change the shape | Flag | Default | What it changes | |---|---|---| | `-controllers`, `--use-controllers` | false | Generates `Controllers/WeatherForecastController.cs` (`[ApiController]`, `[Route("[controller]")]`), `WeatherForecast.cs`, and a `Program.cs` with `AddControllers()`, `UseAuthorization()`, `MapControllers()` | | `--no-openapi` | false | Drops the `Microsoft.AspNetCore.OpenApi` reference, `AddOpenApi()`, `MapOpenApi()` and the `.WithName(...)` call | | `--no-https` | false | Drops the https launch profile and `UseHttpsRedirection()`; ignored for `--auth SingleOrg` and `--auth IndividualB2C`, which require HTTPS | | `--auth` | `None` | `IndividualB2C`, `SingleOrg` or `Windows`; there is no `Individual` choice on `webapi` | | `--use-program-main` | false | An explicit `Program` class with `Main` instead of top-level statements | | `--exclude-launch-settings` | false | No launch-settings file | Two traps hide in that list. `--use-minimal-apis` (`-minimal`) still exists but is **hidden**: Minimal APIs are already the default and `--use-controllers` overrides it. And there is **no opt-in OpenAPI flag** — OpenAPI is on, and `--no-openapi` is the only switch. ## A worked scaffold A courier start-up wants its parcel-locker API on controllers, with no OpenAPI document because the contract is published separately: 1. Run `dotnet new webapi --use-controllers --no-openapi -o ParcelLockers.Api`. 2. Open `Program.cs`: it registers `AddControllers()` and nothing else, then calls `UseHttpsRedirection()`, `UseAuthorization()` and `MapControllers()`. 3. Add a `LockersController` beside the generated `WeatherForecastController`; it needs `using Microsoft.AspNetCore.Mvc;` because that namespace is not one of the Web SDK's implicit usings. The `UseAuthorization()` call is there even without `--auth`; it lets requests through until an endpoint carries authorization metadata such as `[Authorize]`. ## How the defaults got here - **.NET 8** made Minimal APIs the `webapi` default, added `--use-controllers`, and introduced Native AOT as a separate template, `webapiaot`, rather than a `webapi` flag. - **.NET 9** replaced Swashbuckle in the templates with `AddOpenApi` / `MapOpenApi`. - **.NET 10** generates OpenAPI 3.1 documents by default (`OpenApiOptions.OpenApiVersion`). Anyone who learned on .NET 6 or 7 expects `AddSwaggerGen()` and a Swagger UI page at `/swagger`; on a .NET 10 scaffold neither exists until a package is added. ## Interview traps around this template - **"Minimal APIs are only for tiny services."** The default is a starting style, not a size limit; controllers remain fully supported and one flag away. - **"The template is Production-ready as written."** It is a starting point: there is no authentication, no exception handler, no health check and no ProblemDetails setup — each is added deliberately later. - **"OpenAPI must be on to call the API from a client."** The document only describes the API for tooling; `--no-openapi` changes nothing about how requests are served. - **"The `.http` file is a test suite."** It is a scratch request file for an editor's HTTP client, pointed at the local port through a `@..._HostAddress` variable; it is not run by `dotnet test`. - **"Switching later means re-scaffolding."** Moving from Minimal APIs to controllers, or adding OpenAPI after `--no-openapi`, is a few lines in `Program.cs` and one package reference; the flags only choose the starting state.

  • Where is the OpenAPI document of a default .NET 10 webapi project served, and in which environments?
    At `/openapi/v1.json`: `MapOpenApi()` defaults to the pattern `/openapi/{documentName}.json` and the document name `v1`. The template wraps the call in `if (app.Environment.IsDevelopment())`, so Staging and Production do not expose it unless you move the call. No UI is generated; a Swagger UI or Scalar page is a separate package you add.
  • What does --use-minimal-apis do on the .NET 10 webapi template?
    Practically nothing: it is a hidden option whose value already defaults to Minimal APIs. The template computes `UsingControllers` as `UseControllers || !UseMinimalAPIs`, so `--use-controllers` wins whenever both are passed.
  • Why might dotnet new webapi --auth SingleOrg --no-https still produce an HTTPS app?
    Because `SingleOrg` and `IndividualB2C` set the template's `RequiresHttps` condition. The https profile and `UseHttpsRedirection()` stay, and the http-only profile is dropped; `--no-https` only takes effect with `None` or `Windows` authentication.

  • dotnet new webapi adds Swashbuckle with AddSwaggerGen and UseSwaggerUI
  • dotnet new webapi creates a Controllers folder unless you pass --use-minimal-apis
  • Pass --aot to dotnet new webapi for a Native AOT API
  • The template maps MapOpenApi in every environment, so Production serves /openapi/v1.json
  • dotnet new webapi --auth Individual gives the API local Identity accounts

Assumes the ASP.NET Core 10.0 templates: Minimal APIs became the webapi default in .NET 8, built-in OpenAPI replaced Swashbuckle in .NET 9, and 10 emits OpenAPI 3.1.

open as a page

In ASP.NET Core 10, which dotnet new template — web, webapi, webapiaot, mvc, webapp, blazor or grpc — fits which kind of application?

level: juniorimportance: should knowfreq 55%

basics

~20 s

Pick by what the app serves: web for an empty app, webapi for JSON APIs, webapiaot for a Native AOT API, mvc or webapp for server-rendered pages, blazor for a Blazor Web App, and grpc for gRPC services.

open as a page

With ImplicitUsings enabled in a .NET 10 Microsoft.NET.Sdk.Web project, which namespaces are imported automatically, and how do you change that list?

level: middleimportance: should knowfreq 36%

basics

~10 s

The SDK generates global using directives into obj/<Project>.GlobalUsings.g.cs: seven System namespaces plus nine web ones such as Microsoft.AspNetCore.Builder and Microsoft.Extensions.DependencyInjection. Using items in the csproj add, alias or remove entries.

open as a page

In a .NET 10 project file, what does Sdk="Microsoft.NET.Sdk.Web" give a project that plain Microsoft.NET.Sdk does not?

level: middleimportance: should knowfreq 42%

basics

~10 s

Microsoft.NET.Sdk.Web adds an implicit FrameworkReference to the Microsoft.AspNetCore.App shared framework, imports the Razor and Publish SDKs, makes the project an executable with server GC, and adds ASP.NET Core implicit usings and analyzers.

open as a page

A .NET 10 class library holding a courier start-up's shared ASP.NET Core middleware needs HttpContext and ControllerBase — how should its project file reference ASP.NET Core?

level: seniorimportance: should knowfreq 28%

basics

~10 s

Keep the library on Microsoft.NET.Sdk and add FrameworkReference Include="Microsoft.AspNetCore.App". Neither the Web SDK, which makes it an executable, nor a PackageReference to the old metapackage or 2.x Microsoft.AspNetCore.* packages is right.

open as a page