.NET best practices (version-aware, progressive-loading)
Overview
Apply modern .NET platform capabilities and recommended engineering practices across the full
lifecycle of a .NET codebase. This skill covers runtime/framework choices, SDK/tooling,
packaging, deployment strategy, and version-aware best practices for implementation,
maintenance, and code review scenarios.
Purpose
Apply modern .NET platform capabilities and recommended engineering practices across the
full lifecycle of a .NET codebase, including:
- feature implementation and enhancement
- routine maintenance and refactoring
- code review and pull request validation
- runtime/framework upgrades
- production hardening and operational improvements
This skill complements a C# language-focused skill by concentrating on .NET runtime/framework,
hosting, SDK/tooling, packaging, and operational practices.
Upgrade policy (default)
- Default for production: upgrade to the latest LTS .NET version.
- Use STS releases only when a specific platform feature is required and you have an explicit
follow-on plan to land on the latest LTS.
When to use
Use this skill when you are:
- Implementing new .NET features or services
- Modifying existing application or library code
- Reviewing pull requests or performing structured code reviews
- Refactoring or modernizing legacy .NET code
- Upgrading target frameworks, SDKs, or runtime versions
- Validating alignment with current .NET platform best practices
- Establishing or enforcing repository standards for .NET projects
For cross-language or organization-wide security processes, use the security-processes skill alongside this one.
Core Workflow
- Identify target .NET version and load corresponding version reference
- For upgrades, load upgrade-cumulative.md and lts-upgrade-playbook.md
- Apply baseline engineering standards (security, reliability, performance, maintainability)
- Review code against version-specific recommended patterns
- Validate configuration centralisation and analyzer enforcement
- Produce target framework recommendation and adoption checklist
- Document risks, breaking changes, and required test gates
Progressive loading model
- Read this file (baseline standards + operating procedure).
- Load only the references you need:
- Version indexes:
references/dotnet-6.md, references/dotnet-7.md, references/dotnet-8.md, references/dotnet-9.md, references/dotnet-10.md
- If upgrading across majors, also load:
references/upgrade-cumulative.md
references/lts-upgrade-playbook.md
- For .NET-specific security enforcement, load:
references/dotnet-security-tooling.md
- For cross-language security processes (SCA/SBOM/container scanning, policy gates, exception handling), use:
Baseline engineering standards (version-agnostic)
Security
- Prefer secure defaults; do not weaken them without a threat-model justification.
- Enforce HTTPS and HSTS in production; own reverse-proxy/header configuration explicitly.
- Centralize authN/authZ; validate all inbound data; avoid unsafe dynamic deserialization patterns.
- Patch cadence: treat runtime/framework security updates as routine work with defined SLAs.
Reliability
- Ensure graceful shutdown and cancellation propagation (
IHostApplicationLifetime, hosted services).
- Use bounded concurrency, timeouts, and resilience for outbound calls; prevent retry storms.
- Avoid sync-over-async; use async end-to-end for I/O.
Performance
- Measure first: tracing/metrics, baseline benchmarks.
- Avoid allocations on hot paths; use pooling where it materially helps.
- Use Span/Memory-friendly APIs where appropriate (especially in libraries).
- Consider AOT/trimming selectively (CLI, serverless cold-start, edge) once compatibility is validated.
Maintainability & governance
- Centralize build configuration in
Directory.Build.props / Directory.Build.targets.
- Enable analyzers; move toward warnings-as-errors for critical projects/new code.
- Keep nullable reference types enabled and clean (avoid blanket suppressions).
- Standardize package versioning strategy.
- Adopt NuGet Central Package Management (
Directory.Packages.props) as soon as supported
by your toolchain, and enforce "no versions in csproj PackageReference" with documented
exceptions.
Code review lens (how to apply this skill in PRs)
When used during code review, apply this skill to evaluate:
Outputs (what this skill should produce)
- Target framework recommendation (latest LTS) and upgrade plan/backlog.
- Version-specific adoption checklist (what to adopt now vs later).
- Cumulative upgrade checklist when crossing multiple majors.
- Risks/breaking-change checklist and required test gates (contract/perf/integration).
- Repository standards updates (packaging, analyzers, SDK pinning, CI enforcement).
Red Flags - STOP
These statements indicate misalignment with .NET best practices:
| Thought |
Reality |
| "We'll stay on .NET 6 indefinitely" |
LTS versions have end-of-life dates; plan upgrades proactively |
| "Sync-over-async is fine for this case" |
Async should be end-to-end; sync-over-async causes thread pool starvation |
| "We don't need analyzers" |
Analyzers catch issues at compile time; enable and address warnings |
| "NuGet package versions in csproj are fine" |
Use Central Package Management for consistency and security |
| "Security patches can wait" |
Runtime security updates need defined SLAs; treat as routine work |
| "AOT/trimming will just work" |
Validate compatibility before enabling; many patterns are incompatible |
1---2name: dotnet-best-practices3description: Use when designing, implementing, maintaining, or reviewing .NET features, projects, and codebases. Covers architecture, runtime/framework choices, SDK/tooling, packaging, deployment strategy, and version-aware best practices, including code review and ongoing maintenance scenarios.4---56# .NET best practices (version-aware, progressive-loading)78## Overview910Apply modern .NET platform capabilities and recommended engineering practices across the full11lifecycle of a .NET codebase. This skill covers runtime/framework choices, SDK/tooling,12packaging, deployment strategy, and version-aware best practices for implementation,13maintenance, and code review scenarios.1415## Purpose1617Apply modern .NET platform capabilities and recommended engineering practices across the18**full lifecycle** of a .NET codebase, including:1920- feature implementation and enhancement21- routine maintenance and refactoring22- code review and pull request validation23- runtime/framework upgrades24- production hardening and operational improvements2526This skill complements a C# language-focused skill by concentrating on .NET runtime/framework,27hosting, SDK/tooling, packaging, and operational practices.2829## Upgrade policy (default)3031- Default for production: **upgrade to the latest LTS .NET version**.32- Use STS releases only when a specific platform feature is required and you have an explicit33 follow-on plan to land on the latest LTS.3435## When to use3637Use this skill when you are:3839- Implementing new .NET features or services40- Modifying existing application or library code41- Reviewing pull requests or performing structured code reviews42- Refactoring or modernizing legacy .NET code43- Upgrading target frameworks, SDKs, or runtime versions44- Validating alignment with current .NET platform best practices45- Establishing or enforcing repository standards for .NET projects4647For cross-language or organization-wide security processes, use the `security-processes` skill alongside this one.4849## Core Workflow50511. Identify target .NET version and load corresponding version reference522. For upgrades, load upgrade-cumulative.md and lts-upgrade-playbook.md533. Apply baseline engineering standards (security, reliability, performance, maintainability)544. Review code against version-specific recommended patterns555. Validate configuration centralisation and analyzer enforcement566. Produce target framework recommendation and adoption checklist577. Document risks, breaking changes, and required test gates5859## Progressive loading model60611. Read this file (baseline standards + operating procedure).622. Load only the references you need:6364- Version indexes:65 - `references/dotnet-6.md`, `references/dotnet-7.md`, `references/dotnet-8.md`, `references/dotnet-9.md`, `references/dotnet-10.md`66- If upgrading across majors, also load:67 - `references/upgrade-cumulative.md`68 - `references/lts-upgrade-playbook.md`69- For .NET-specific security enforcement, load:70 - `references/dotnet-security-tooling.md`71- For cross-language security processes (SCA/SBOM/container scanning, policy gates, exception handling), use:72 - `security-processes` skill7374## Baseline engineering standards (version-agnostic)7576### Security7778- Prefer secure defaults; do not weaken them without a threat-model justification.79- Enforce HTTPS and HSTS in production; own reverse-proxy/header configuration explicitly.80- Centralize authN/authZ; validate all inbound data; avoid unsafe dynamic deserialization patterns.81- Patch cadence: treat runtime/framework security updates as routine work with defined SLAs.8283### Reliability8485- Ensure graceful shutdown and cancellation propagation (`IHostApplicationLifetime`, hosted services).86- Use bounded concurrency, timeouts, and resilience for outbound calls; prevent retry storms.87- Avoid sync-over-async; use async end-to-end for I/O.8889### Performance9091- Measure first: tracing/metrics, baseline benchmarks.92- Avoid allocations on hot paths; use pooling where it materially helps.93- Use Span/Memory-friendly APIs where appropriate (especially in libraries).94- Consider AOT/trimming selectively (CLI, serverless cold-start, edge) once compatibility is validated.9596### Maintainability & governance9798- Centralize build configuration in `Directory.Build.props` / `Directory.Build.targets`.99- Enable analyzers; move toward warnings-as-errors for critical projects/new code.100- Keep nullable reference types enabled and clean (avoid blanket suppressions).101- Standardize package versioning strategy.102- Adopt **NuGet Central Package Management** (`Directory.Packages.props`) as soon as supported103 by your toolchain, and enforce "no versions in csproj PackageReference" with documented104 exceptions.105106## Code review lens (how to apply this skill in PRs)107108When used during code review, apply this skill to evaluate:109110- **Platform alignment**111 - Is the code aligned with the target .NET version's recommended patterns?112 - Are deprecated or superseded APIs being introduced?113114- **Runtime and performance awareness**115 - Does the change introduce unnecessary allocations, sync-over-async, or blocking I/O?116 - Are newer runtime/library capabilities being ignored where they would simplify or harden the code?117118- **Security posture**119 - Does the change unnecessarily widen the public API surface?120 - Are defaults being weakened (auth, HTTPS, serialization, validation)?121122- **Maintainability**123 - Are analyzers respected or suppressed without justification?124 - Is configuration, dependency management, and hosting consistent with repo standards?125126- **Upgrade readiness**127 - Will this change make future LTS upgrades harder (tight coupling, legacy patterns, hidden assumptions)?128129## Outputs (what this skill should produce)130131- Target framework recommendation (latest LTS) and upgrade plan/backlog.132- Version-specific adoption checklist (what to adopt now vs later).133- Cumulative upgrade checklist when crossing multiple majors.134- Risks/breaking-change checklist and required test gates (contract/perf/integration).135- Repository standards updates (packaging, analyzers, SDK pinning, CI enforcement).136137## Red Flags - STOP138139These statements indicate misalignment with .NET best practices:140141| Thought | Reality |142| ------------------------------------------- | ------------------------------------------------------------------------- |143| "We'll stay on .NET 6 indefinitely" | LTS versions have end-of-life dates; plan upgrades proactively |144| "Sync-over-async is fine for this case" | Async should be end-to-end; sync-over-async causes thread pool starvation |145| "We don't need analyzers" | Analyzers catch issues at compile time; enable and address warnings |146| "NuGet package versions in csproj are fine" | Use Central Package Management for consistency and security |147| "Security patches can wait" | Runtime security updates need defined SLAs; treat as routine work |148| "AOT/trimming will just work" | Validate compatibility before enabling; many patterns are incompatible |