Skip to content
Skillpedia
General coding40k · #5120

dotnet-best-practices

Helps your agent ensure .NET/C# code follows best practices. It checks if the code is well-written and efficient.

What it does

This AI agent helps ensure your .NET/C# code follows recommended best practices. It checks for documentation, structure, design pattern usage, dependency injection, resource management, async/await usage, testing, configuration, AI integration, error handling, security, and overall code quality.

When to use it

  • ✓When writing new C# code.
  • ✓When reviewing existing code.
  • ✓When optimizing for performance or security.

Example of what to ask your AI

“Check if this C# code follows best practices.”

Want more? Open the sections below.

How to use

The easiest way: copy the message below and paste it into Claude, ChatGPT, Cursor or any AI. It reads the skill and follows the instructions.

Skill link

https://github.com/github/awesome-copilot/blob/main/skills/dotnet-best-practices/SKILL.md

Ready-to-paste message

Use this skill to help me: https://github.com/github/awesome-copilot/blob/main/skills/dotnet-best-practices/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
How it works

The agent analyzes your code for specific patterns, such as proper documentation, use of design patterns, and correct error handling. It compares your code against a set of rules and suggests improvements.

Installation

Easiest way: copy the skill link and paste it into Claude, ChatGPT or Cursor asking it to follow the instructions.

In the terminal (Claude Code, Codex, Cursor), in your project folder:

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

Or download just the file:

curl -L https://raw.githubusercontent.com/github/awesome-copilot/main/skills/dotnet-best-practices/SKILL.md -o SKILL.md
Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

.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
FAQ

What are 'best practices'?

These are the most efficient and secure ways to write code, making it easier to maintain and avoiding common errors.

Do I need to understand all the technical terms to use this agent?

No, the agent is designed to help even if you are not an experienced programmer. It focuses on applying rules that improve code quality.

Can the agent fix my code automatically?

This agent focuses on identifying and suggesting improvements. Automatic correction may depend on other tools or your own intervention.

Details

Original description by the author

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

repo: github/awesome-copilot

Popularity

GitHub stars
40k
Ranking position
#5120
License
MIT
Updated
10/15/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills