Generated banner for Dotnet Best Practices
Generated logo for Dotnet Best Practices

Dotnet Best Practices

GitHubOfficialOriginally contributed by @PlagueHO as prompts/dotnet-best-practices.prompt.md; moved into a skill by pull request #761Distributed by GitHub

  • Skill
  • Guidelines
  • Software development
  • MIT
  • No issues found

From the author

Ensure .NET/C# code meets best practices for the solution/project.
— the description by PlagueHO

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides a structured framework of best practices for .NET and C# projects. It covers a wide range of development areas including documentation, dependency injection, asynchronous programming, testing, configuration, and AI integration using Semantic Kernel. It serves as a reference for maintaining consistent code structure, performance, and security across .NET solutions.

What it does

  • Defines standards for XML documentation and namespace organization.
  • Outlines architectural patterns like Command Handler, Factory, and SOLID principles.
  • Provides guidelines for dependency injection and service lifetime management.
  • Specifies patterns for async/await, resource management, and structured logging.
  • Sets requirements for testing with MSTest, FluentAssertions, and Moq.
  • Details configuration management and AI integration via Microsoft.SemanticKernel.

When to use it

  • When establishing coding standards for a new .NET project.
  • During code reviews to ensure alignment with established architectural patterns.
  • When refactoring existing C# code to improve maintainability and testability.
  • When implementing new features that require AI integration or configuration management.

Advantages

  • Promotes consistency across the codebase through defined naming and structure conventions.
  • Encourages testable code through interface segregation and dependency injection.
  • Provides clear guidance on modern .NET 8 and C# 12+ features.
  • Ensures robust error handling and logging practices are applied uniformly.

Usage examples

“Review my current service implementation against the .NET best practices.”
The agent evaluates the service code against the provided guidelines, checking for proper dependency injection, XML documentation, and async/await usage.
“How should I structure my new feature using the Command Handler pattern?”
The agent provides a template or guidance on implementing the Command Handler pattern with generic base classes as defined in the guidelines.

Install

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/github/dotnet-best-practices/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip dotnet-best-practices.zip -d .agents/skills

Documentation by PlagueHO

.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

Files

Requirements and compatibility

Written for: GitHub Copilot

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Originally contributed by
GitHub avatar of PlagueHO@PlagueHOas prompts/dotnet-best-practices.prompt.mdmoved into a skill by pull request #761
Publisher
GitHub (Official)
Distributed by
GitHub
Source
github/awesome-copilot · skills/dotnet-best-practices · commit 797337f
Licence
MIT License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced
Contributors
PlagueHO

AutoGineer is not affiliated with or endorsed by PlagueHO or GitHub.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download dotnet-best-practices.zip