Home › .NET / ASP.NET Core › ASP.NET Core Copilot instructions

ASP.NET Core Copilot instructions

Copilot instructions for ASP.NET Core on .NET 9/10: minimal APIs, EF Core, nullable types, and xUnit tests.

GitHub Copilot.NET / ASP.NET Core

How to use

Save this as .github/copilot-instructions.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

Note: Review and test before use. Provided as is, without warranty. See Terms.

.github/copilot-instructions.mdDownload  
# ASP.NET Core (.NET 9/10) instructions

## Commands
`dotnet build -warnaserror` · `dotnet test` · `dotnet format --verify-no-changes`

## Conventions
- Nullable reference types are on; fix warnings, don't suppress them with `!`.
- Minimal APIs grouped per feature with `MapGroup("/orders")` in an extension method (`app.MapOrders()`). Return `TypedResults` (`Results<Ok<OrderDto>, NotFound>`) so OpenAPI is accurate.
- DTOs are `record`s. Never return EF entities.
- Validate input (FluentValidation or DataAnnotations, whichever the repo uses) and return `TypedResults.ValidationProblem`.
- Errors produce `ProblemDetails` via `AddProblemDetails()` and an exception handler; no try/catch in every endpoint.
- Async all the way: `async Task`, pass `CancellationToken` from the endpoint down to EF calls. No `.Result` or `.Wait()`.
- EF Core: `AsNoTracking()` for reads, projections with `Select` to DTOs, migrations with `dotnet ef migrations add <Name>`.
- Options pattern (`IOptions<T>` with validation) for config. Secrets via user-secrets locally, never `appsettings.json`.
- Logging via `ILogger<T>` with message templates (`"Order {OrderId} shipped"`), not string interpolation.

## Tests
xUnit + `WebApplicationFactory<Program>` for endpoint tests; Testcontainers for the database.

## Don't
Don't add MediatR or a repository layer over EF unless the project already has one.

More: all .NET / ASP.NET Core rules · all GitHub Copilot rules

Related rules

Blazor (.NET 10) AGENTS.md

AGENTS.md for Blazor Web Apps on .NET 10: render modes, components, forms and validation, state, and bUnit tests.

AGENTS.md.NET / ASP.NET Core

C# / .NET Copilot path instructions

Path-specific Copilot instructions for C# files on .NET 10: nullable types, async, records, and logging.

GitHub Copilot.NET / ASP.NET Core

Go Copilot path instructions

Path-specific Copilot instructions (.instructions.md) for Go 1.27 code: errors, context, stdlib routing, and tests.

GitHub CopilotGo

Java + Gradle Copilot path instructions

Path-specific Copilot instructions for Java 25 LTS code built with Gradle: records, null safety, and JUnit 5 tests.

GitHub CopilotJava

Laravel Copilot instructions

GitHub Copilot instructions for Laravel 11+ apps with Eloquent, Pest, and Form Requests.

GitHub CopilotLaravel

Modern PHP Copilot path instructions

Path-specific Copilot instructions for PHP 8.4 code: strict types, typed properties, enums, readonly, and PSR-12.

GitHub CopilotPHP

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.