Skip to main content
skill GitHub Copilot official · GitHub

dotnet-best-practices — GitHub Copilot skill

Guides reviews and edits of selected .NET/C# code with project rules for structure, DI, tests, logging and security. Use it when changing an existing solution.

Install into GitHub Copilot · Skills CLI (Vercel) All methods and platforms ↓
npx skills add github/awesome-copilot --skill dotnet-best-practices
Open on GitHub

What dotnet-best-practices does

This skill guides GitHub Copilot when it edits selected C# code. It calls for XML documentation on public APIs, namespaces in the {Core|Console|App|Service}.{Feature} form, clear domain names and focused methods. It also suggests Factory for complex object creation and generic Command Handler base classes for commands.

The rules cover constructor injection with ArgumentNullException, Microsoft.Extensions.DependencyInjection lifetimes and service interfaces for testing. They include async/await, Task, ConfigureAwait(false), ResourceManager localisation, strongly typed settings and appsettings.json. Test guidance uses MSTest, FluentAssertions, Moq and the Arrange, Act, Assert pattern.

It further asks for structured logging, specific exceptions, input validation and parameterised database queries. Microsoft.SemanticKernel guidance covers service registration plus ChatCompletion and Embedding settings. Install it if your project follows these libraries and patterns; teams using different testing or DI conventions should skip it because it will push the wrong house style.

What it helps with

  • add XML documentation to public APIs
  • apply constructor dependency injection with null checks
  • write MSTest cases for success and failure paths
  • move I/O work to async/await methods
  • use structured logging with useful context

Example prompts for the agent

  • Review the selected C# code using dotnet-best-practices.
  • Add XML documentation and fix dependency injection in this class.
  • Write MSTest tests with FluentAssertions and Moq for this command handler.

How to install dotnet-best-practices

1Skills CLI (Vercel)

npx skills add github/awesome-copilot --skill dotnet-best-practices

2GitHub CLI

gh skill install github/awesome-copilot dotnet-best-practices

3Manually: put the files in place

.github/skills/dotnet-best-practices/SKILL.md

From the same set554

The whole set →
git-commit official github This skill reviews Git changes, stages related files, and creates Conventional Commits. Use it when you want an agent to make one commit or split work into separate commits. GitHub Copilot 47,165installs excalidraw-diagram-generator official github Turn a plain-language description into an Excalidraw diagram. Useful for mapping processes, system structure, and relationships between entities. GitHub Copilot 31,639installs multi-stage-dockerfile official github This skill guides GitHub Copilot in writing multi-stage Dockerfiles for different languages and frameworks. Use it when the final runtime image should contain fewer build dependencies. GitHub Copilot 29,688installs documentation-writer official github Skill that turns the agent into a technical writer following the Diátaxis framework: tutorials, how-to guides, reference, and explanation. Proposes structure before writing. GitHub Copilot 27,757installs prd official github Turns a feature idea into a structured PRD with user stories, technical requirements, and risks. Use it when planning a software feature or an AI-powered one. GitHub Copilot 24,035installs refactor official github This skill reshapes existing code without changing its external behavior. Use it for gradual cleanup of large functions, duplication, weak types, and code smells. GitHub Copilot 22,321installs java-springboot official github Gives GitHub Copilot Spring Boot development practices, from project layout to tests and security. Use it when writing or reviewing Java application code. GitHub Copilot 21,272installs create-readme official github This skill reviews a project and creates a structured README.md. Use it when the repository needs clear documentation based on its actual files and code. GitHub Copilot 19,081installs

Similar

golang-testing affaan-m A skill that gives your agent Go testing patterns: table-driven cases, subtests, benchmarks, fuzzing and coverage. Useful when you write tests and want idiomatic Go. Claude Code CX Codex Cursor +1 5,000installs java-coding-standards affaan-m This skill applies Java conventions to Spring Boot and Quarkus code. Use it when an agent writes or reviews services built with either framework. Claude Code CX Codex Cursor +1 5,000installs rust-patterns affaan-m Guides your coding agent to write idiomatic Rust using strict ownership rules, typed errors, Cow, and exhaustive pattern matching. Claude Code CX Codex Cursor +1 5,000installs nodejs-keccak256 affaan-m Catches NIST SHA3 used where Ethereum expects Keccak-256. Useful when a selector, signature or storage slot comes out wrong. Claude Code CX Codex Cursor +1 4,800installs kotlin-patterns affaan-m Guides AI agents through idiomatic Kotlin conventions, null safety, and coroutine patterns. Useful for code reviews and refactoring Java-like Kotlin. Claude Code CX Codex Cursor +1 4,800installs kotlin-coroutines-flows affaan-m This skill covers Kotlin Coroutines and Flow patterns for Android and KMP. Use it when handling cancellation, concurrent work, reactive state, or tests. Claude Code CX Codex Cursor +1 4,800installs migrate-to-shoehorn Matt Pocock Replaces as type assertions in tests with helpers from @total-typescript/shoehorn. Use it when tests need partial objects or deliberately invalid data. Claude Code 475,388installs write-swift emilkowalski This skill guides Swift coding, reviews, and migrations using the language’s current practices. Use it to investigate concurrency errors, hangs, data races, or retain cycles. Claude Code CX Codex Cursor +1 117,500installs

Questions about dotnet-best-practices

How do I install dotnet-best-practices in GitHub Copilot?

Run npx skills add github/awesome-copilot --skill dotnet-best-practices. You can also use gh skill install github/awesome-copilot dotnet-best-practices.

What does dotnet-best-practices do?

It gives GitHub Copilot rules for selected .NET/C# code, covering documentation, architecture, DI, asynchronous code, testing, configuration and error handling.

Which test tools does dotnet-best-practices use?

Its test rules use MSTest and FluentAssertions, with Moq for dependency mocks. They follow Arrange, Act, Assert and include success, failure and null-parameter cases.

Source text

SKILL.md · MIT
---
name: dotnet-best-practices
description: 'Ensure .NET/C# code meets best practices for the solution/project.'
---

# .NET/C# Best Practices

Your task is to ensure .NET/C# code in ${selection} meets the best practices specific to this solution/project. This includes:

## Documentation & Structure

- Create comprehensive XML documentation comments for all public classes, interfaces, methods, and properties
- Include parameter descriptions and return value descriptions in XML comments
- Follow the established namespace structure: {Core|Console|App|Service}.{Feature}

## Design Patterns & Architecture

- Use primary constructor syntax for dependency injection (e.g., `public class MyClass(IDependency dependency)`)
- Implement the Command Handler pattern with generic base classes (e.g., `CommandHandler<TOptions>`)
- Use interface segregation with clear naming conventions (prefix interfaces with 'I')
- Follow the Factory pattern for complex object creation.

## Dependency Injection & Services

- Use constructor dependency injection with null checks via ArgumentNullException
- Register services with appropriate lifetimes (Singleton, Scoped, Transient)
- Use Microsoft.Extensions.DependencyInjection patterns
- Implement service interfaces for testability

## Resource Management & Localization

- Use ResourceManager for localized messages and error strings
- Separate LogMessages and ErrorMessages resource files
- Access resources via `_resourceManager.GetString("MessageKey")`

## Async/Await Patterns

- Use async/await for all I/O operations and long-running tasks
- Return Task or Task<T> from async methods
- Use ConfigureAwait(false) where appropriate
- Handle async exceptions properly

## Testing Standards

- Use MSTest framework with FluentAssertions for assertions
- Follow AAA pattern (Arrange, Act, Assert)
- Use Moq for mocking dependencies
- Test both success and failure scenarios
- Include null parameter validation tests

## Configuration & Settings

- Use strongly-typed configuration classes with data annotations
- Implement validation attributes (Required, NotEmptyOrWhitespace)
- Use IConfiguration binding for settings
- Support appsettings.json configuration files

## Semantic Kernel & AI Integration

- Use Microsoft.SemanticKernel for AI operations
- Implement proper kernel configuration and service registration
- Handle AI model settings (ChatCompletion, Embedding, etc.)
- Use structured output patterns for reliable AI responses

## Error Handling & Logging

- Use structured logging with Microsoft.Extensions.Logging
- Include scoped logging with meaningful context
- Throw specific exceptions with descriptive messages
- Use try-catch blocks for expected failure scenarios

## Performance & Security

- Use C# 12+ features and .NET 8 optimizations where applicable
- Implement proper input validation and sanitization
- Use parameterized queries for database operations
- Follow secure coding practices for AI/ML operations

## Code Quality

- Ensure SOLID principles compliance
- Avoid code duplication through base classes and utilities
- Use meaningful names that reflect domain concepts
- Keep methods focused and cohesive
- Implement proper disposal patterns for resources

© github · MIT · github/awesome-copilot

See also

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor