Home › .NET / ASP.NET Core › C# / .NET Copilot path instructions

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

How to use

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

.github/instructions/csharp.instructions.mdDownload  
---
applyTo: "**/*.cs"
description: C# conventions
---

# C# (.NET 10)

- Nullable reference types are enabled. Model optionality with `?` and handle it; don't use `!` to silence warnings.
- File-scoped namespaces, primary constructors for DI-only classes, `record` for immutable data, collection expressions (`[]`).
- Async I/O everywhere: `async Task`/`ValueTask`, accept and pass `CancellationToken`, never `.Result`/`.Wait()`/`async void` (except event handlers).
- Use `ILogger<T>` with message templates (`"Processing {OrderId}"`), not interpolated strings.
- Guard clauses with `ArgumentNullException.ThrowIfNull(x)` / `ArgumentException.ThrowIfNullOrEmpty(s)`.
- Prefer pattern matching (`is`, `switch` expressions) over casts and long if/else chains.
- LINQ for clarity, loops for hot paths; materialize EF queries once (`ToListAsync`).
- `IDisposable`/`IAsyncDisposable` resources in `using`/`await using`.
- Configuration via the options pattern with validation (`ValidateOnStart`).
- Public APIs get XML doc comments.

## Check
`dotnet build -warnaserror && dotnet test && dotnet format --verify-no-changes`.

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

Related rules

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

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

Python Copilot path instructions

Path-specific Copilot instructions for Python 3.12+ files: typing, error handling, uv/ruff tooling, and pytest.

GitHub CopilotPython

Ruby on Rails Copilot instructions

GitHub Copilot custom instructions for Rails 8 apps with Hotwire, RSpec and Rubocop.

GitHub CopilotRuby on Rails

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.