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.
npx skills add github/awesome-copilot --skill dotnet-best-practicesWhat 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-practices2GitHub CLI
gh skill install github/awesome-copilot dotnet-best-practices3Manually: put the files in place
.github/skills/dotnet-best-practices/SKILL.md1Skills CLI (Vercel)
npx skills add github/awesome-copilot --skill dotnet-best-practices -a claude-code2Manually: put the files in place
~/.claude/skills/dotnet-best-practices/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/dotnet-best-practices/
Manually: put the files in place
.agents/skills/dotnet-best-practices/SKILL.mdFor all projects use ~/.agents/skills/
Manually: put the files in place
.cursor/skills/dotnet-best-practices/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
Platform CLI
gemini skills install https://github.com/github/awesome-copilot --path skills/dotnet-best-practicesManually: put the files in place
.devin/skills/dotnet-best-practices/SKILL.mdThe legacy .windsurf/skills/ path still works
Claude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
From the same set554
The whole set →Similar
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