PluginBench
Skill
Official
Review
Audit score 70

dotnet-best-practices

github/awesome-copilot

Ensure .NET/C# code meets best practices for your solution/project.

What is dotnet-best-practices?

Validates and improves .NET/C# code against established best practices including documentation, design patterns, dependency injection, async patterns, testing, and security. Use this when writing or reviewing C# code to maintain consistency and quality across your codebase.

  • Create comprehensive XML documentation comments for public classes, interfaces, methods, and properties
  • Enforce design patterns including Command Handler, Factory, and interface segregation with proper naming
  • Implement constructor dependency injection with null checks and appropriate service lifetimes
  • Apply async/await patterns for I/O and long-running operations with proper exception handling
  • Validate testing standards using MSTest, FluentAssertions, and Moq with AAA pattern
  • Ensure structured logging, error handling, and resource management with ResourceManager for localization

How to install dotnet-best-practices

npx skills add https://github.com/github/awesome-copilot --skill dotnet-best-practices
Claude Code
Cursor
Windsurf
Cline

How to use dotnet-best-practices

  1. 1.Select the .NET/C# code or file you want to validate
  2. 2.Run the skill to analyze against best practices guidelines
  3. 3.Review recommendations for documentation, patterns, dependency injection, and testing
  4. 4.Apply suggested changes to align with project standards
  5. 5.Re-run to verify improvements meet the established practices

Use cases

Good for
  • Review new C# classes to ensure XML documentation and proper dependency injection setup
  • Validate async method implementations follow ConfigureAwait and exception handling patterns
  • Check test coverage includes success/failure scenarios and null parameter validation
  • Ensure configuration classes use data annotations and IConfiguration binding
  • Verify Semantic Kernel AI integration follows proper kernel configuration and structured output patterns
Who it's for
  • C# developers building .NET applications
  • Teams maintaining shared .NET codebases with established patterns
  • Developers integrating Semantic Kernel for AI operations
  • QA engineers reviewing code quality and test coverage

dotnet-best-practices FAQ

What .NET versions and C# features does this cover?

The skill targets .NET 8 and C# 12+ features, including primary constructor syntax, async/await patterns, and modern dependency injection with Microsoft.Extensions.DependencyInjection.

Does this skill check for Semantic Kernel integration?

Yes, it validates Microsoft.SemanticKernel usage including kernel configuration, service registration, model settings (ChatCompletion, Embedding), and structured output patterns.

What testing framework does this enforce?

The skill enforces MSTest framework with FluentAssertions for assertions and Moq for mocking dependencies, following the AAA (Arrange, Act, Assert) pattern.

Can this skill validate configuration and localization?

Yes, it checks for strongly-typed configuration classes with data annotations, IConfiguration binding, appsettings.json support, and ResourceManager usage for localized messages.

Does it cover security and performance considerations?

Yes, the skill includes validation for input sanitization, parameterized queries, secure AI/ML practices, and C# 12+ optimizations for .NET 8.

Full instructions (SKILL.md)

Source of truth, from github/awesome-copilot.


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