Added a comprehensive playbook for upgrading .NET projects, including guidance on discovery, analysis, upgrade sequences, and CI/CD configuration.
5.4 KiB
.NET Upgrade — Chatmode Guidance
Purpose: A generic, ChatGPT-first (chatmode) playbook to discover, plan, execute, and validate .NET upgrades for any multi-project solution. This version automatically adapts to the repository’s current .NET version and provides context-aware upgrade guidance to the next stable version.
Quick Start
- Run a discovery pass to enumerate all
*.slnand*.csprojfiles in the repository. - Detect the current .NET version(s) used across projects.
- Identify the latest available stable .NET version (LTS preferred) — usually
+2years ahead of the existing version. - Generate an upgrade plan to move from current → next stable version (e.g.,
net6.0 → net8.0, ornet7.0 → net9.0). - Upgrade one project at a time, validate builds, update tests, and modify CI/CD accordingly.
Auto-Detect Current .NET Version
To automatically detect the current framework versions across the solution:
# 1. Check global SDKs installed
dotnet --list-sdks
# 2. Detect project-level TargetFrameworks
find . -name "*.csproj" -exec grep -H "<TargetFramework" {} \;
# 3. Optional: summarize unique framework versions
grep -r "<TargetFramework" **/*.csproj | sed 's/.*<TargetFramework>//;s/<\/TargetFramework>//' | sort | uniq
# 4. Verify runtime environment
dotnet --info | grep "Version"
Chat Prompt:
"Analyze the repository and list each project’s current TargetFramework along with the latest available LTS version from Microsoft’s release schedule."
Discovery & Analysis Commands
# List all projects
dotnet sln list
# Check current target frameworks for each project
grep -H "TargetFramework" **/*.csproj
# Check outdated packages
dotnet list <ProjectName>.csproj package --outdated
# Generate dependency graph
dotnet msbuild <ProjectName>.csproj /t:GenerateRestoreGraphFile /p:RestoreGraphOutputPath=graph.json
Chat Prompt:
"Analyze the solution and summarize each project’s current TargetFramework and suggest the appropriate next LTS upgrade version."
Classification Rules
TargetFrameworkstarts withnetcoreapp,net5.0+,net6.0+, etc. → Modern .NETnetstandard*→ .NET Standard (migrate to current .NET version)net4*→ .NET Framework (migrate via intermediate step to .NET 6+)
Upgrade Sequence
- Start with Independent Libraries: Least dependent class libraries first.
- Next: Shared components and common utilities.
- Then: API, Web, or Function projects.
- Finally: Tests, integration points, and pipelines.
Chat Prompt:
"Generate the optimal upgrade order for this repository, prioritizing least-dependent projects first."
Per-Project Upgrade Flow
- Create branch:
upgrade/<project>-to-<targetVersion> - Edit
<TargetFramework>in.csprojto the suggested version (e.g.,net9.0) - Restore & update packages:
dotnet restore dotnet list package --outdated dotnet add package <PackageName> --version <LatestVersion> - Build & test:
dotnet build <ProjectName>.csproj dotnet test <ProjectName>.Tests.csproj - Fix issues — resolve deprecated APIs, adjust configurations, modernize JSON/logging/DI.
- Commit & push PR with test evidence and checklist.
Breaking Changes & Modernization
- Use
.NET Upgrade Assistantfor initial recommendations. - Apply analyzers to detect obsolete APIs.
- Replace outdated SDKs (e.g.,
Microsoft.Azure.*→Azure.*). - Modernize startup logic (
Startup.cs→Program.cstop-level statements).
Chat Prompt:
"List deprecated or incompatible APIs when upgrading from to for ."
CI/CD Configuration Updates
Ensure pipelines use the detected target version dynamically:
Azure DevOps
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '$(TargetDotNetVersion).x'
GitHub Actions
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '${{ env.TargetDotNetVersion }}.x'
Validation Checklist
- TargetFramework upgraded to next stable version
- All NuGet packages compatible and updated
- Build and test pipelines succeed locally and in CI
- Integration tests pass
- Deployed to a lower environment and verified
Branching & Rollback Strategy
- Use feature branches:
upgrade/<project>-to-<targetVersion> - Commit frequently and keep changes atomic
- If CI fails after merge, revert PR and isolate failing modules
Chat Prompt:
"Suggest a rollback and validation plan if the .NET upgrade for introduces build or runtime regressions."
Automation & Scaling
- Automate upgrade detection with GitHub Actions or Azure Pipelines.
- Schedule nightly runs to check for new .NET releases via
dotnet --list-sdks. - Use agents to automatically raise PRs for outdated frameworks.
Chatmode Prompt Library
- "List all projects with current and recommended .NET versions."
- "Generate a per-project upgrade plan from to ."
- "Suggest .csproj and pipeline edits to upgrade ."
- "Summarize build/test results post-upgrade for ."
- "Create PR description and checklist for the upgrade."
End of chatmode playbook — adaptive across any .NET version. Detects the current repo version and provides upgrade paths, scripts, and validation steps dynamically.