All skills
github avatar

/dotnet-best-practices

@90921cc official
by githubgithub/awesome-copilot40k stars
5,040

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

Use this Skill: https://skilld.dev/gh/github/awesome-copilot/dotnet-best-practices

This session only. Nothing lands on disk.

SKILL.md

≈22 tokens always: the name and description. ≈778 when used: this file.

.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

Source: SKILL.md on GitHub

1 warning16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    This skill provides a set of architectural and coding guidelines for .NET/C# development. It focuses on documentation, design patterns, testing, and security best practices without performing any active operations or including external scripts.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer7mo

    1/1 file flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 90921cc. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 18 hours ago.

Activeupdated 5 months ago
  • Testing
  • dotnet
  • csharp
  • best-practices
  • architecture
  • dependency-injection
  • mstest
  • semantic-kernel
  • async-await
  • logging

README badge

README badge for github/awesome-copilot/dotnet-best-practices

Ensures .NET/C# code follows project-specific best practices including XML documentation, primary constructors, dependency injection, async patterns, MSTest with FluentAssertions, and structured logging. Covers design patterns, configuration validation, resource management, and Semantic Kernel integration for AI operations.

Generated from the current SKILL.md.

Does this skill work with C# versions older than 12?
The skill recommends C# 12+ features and .NET 8 optimizations, but the best practices it covers (XML docs, DI patterns, async/await, MSTest) apply to earlier versions. You may need to adapt syntax like primary constructors if targeting older C# versions.
What testing framework does this skill assume?
MSTest with FluentAssertions for assertions and Moq for mocking dependencies. Tests follow the AAA pattern and cover both success and failure scenarios.
Does this skill cover database operations?
Yes. The skill requires parameterized queries for database operations and mentions ResourceManager for localized messages, but does not prescribe a specific ORM or database library.
What does this skill expect regarding dependency injection?
Constructor injection using primary constructor syntax, null checks via ArgumentNullException, and registration with Microsoft.Extensions.DependencyInjection with appropriate lifetimes (Singleton, Scoped, Transient).
Does this skill provide guidance on Semantic Kernel integration?
Yes. The skill includes best practices for Microsoft.SemanticKernel, including kernel configuration, service registration, AI model settings, and structured output patterns for reliable AI responses.

Generated from the current SKILL.md. These answers refresh after source changes.