|
| 1 | +--- |
| 2 | +description: 'Perform janitorial tasks on C#/.NET code including cleanup, modernization, and tech debt remediation.' |
| 3 | +tools: ['codebase', 'edit/editFiles', 'search', 'runCommands', 'runTasks', 'runTests', 'problems', 'changes', 'usages', 'findTestFiles', 'testFailure', 'terminalLastCommand', 'terminalSelection', 'fetch', 'microsoft.docs.mcp'] |
| 4 | +--- |
| 5 | + |
| 6 | +# .NET Upgrade Collection |
| 7 | + |
| 8 | +.NET Framework upgrade specialist for comprehensive project migration |
| 9 | + |
| 10 | +**Tags:** dotnet, upgrade, migration, framework, modernization |
| 11 | + |
| 12 | +## Collection Usage |
| 13 | + |
| 14 | +### .NET Upgrade Chat Mode |
| 15 | + |
| 16 | +Discover and plan your .NET upgrade journey! |
| 17 | + |
| 18 | +```markdown, upgrade-analysis.prompt.md |
| 19 | +--- |
| 20 | +mode: dotnet-upgrade |
| 21 | +title: Analyze current .NET framework versions and create upgrade plan |
| 22 | +--- |
| 23 | +Analyze the repository and list each project's current TargetFramework |
| 24 | +along with the latest available LTS version from Microsoft's release schedule. |
| 25 | +Create an upgrade strategy prioritizing least-dependent projects first. |
| 26 | +``` |
| 27 | + |
| 28 | +The upgrade chat mode automatically adapts to your repository's current .NET version and provides context-aware upgrade guidance to the next stable version. |
| 29 | + |
| 30 | +It will help you: |
| 31 | +- Auto-detect current .NET versions across all projects |
| 32 | +- Generate optimal upgrade sequences |
| 33 | +- Identify breaking changes and modernization opportunities |
| 34 | +- Create per-project upgrade flows |
| 35 | + |
| 36 | +--- |
| 37 | + |
| 38 | +### .NET Upgrade Instructions |
| 39 | + |
| 40 | +Execute comprehensive .NET framework upgrades with structured guidance! |
| 41 | + |
| 42 | +The instructions provide: |
| 43 | +- Sequential upgrade strategies |
| 44 | +- Dependency analysis and sequencing |
| 45 | +- Framework targeting and code adjustments |
| 46 | +- NuGet and dependency management |
| 47 | +- CI/CD pipeline updates |
| 48 | +- Testing and validation procedures |
| 49 | + |
| 50 | +Use these instructions when implementing upgrade plans to ensure proper execution and validation. |
| 51 | + |
| 52 | +--- |
| 53 | + |
| 54 | +### .NET Upgrade Prompts |
| 55 | + |
| 56 | +Quick access to specialized upgrade analysis prompts! |
| 57 | + |
| 58 | +The prompts collection includes ready-to-use queries for: |
| 59 | +- Project discovery and assessment |
| 60 | +- Upgrade strategy and sequencing |
| 61 | +- Framework targeting and code adjustments |
| 62 | +- Breaking change analysis |
| 63 | +- CI/CD pipeline updates |
| 64 | +- Final validation and delivery |
| 65 | + |
| 66 | +Use these prompts for targeted analysis of specific upgrade aspects. |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +## Quick Start |
| 71 | +1. Run a discovery pass to enumerate all `*.sln` and `*.csproj` files in the repository. |
| 72 | +2. Detect the current .NET version(s) used across projects. |
| 73 | +3. Identify the latest available stable .NET version (LTS preferred) — usually `+2` years ahead of the existing version. |
| 74 | +4. Generate an upgrade plan to move from current → next stable version (e.g., `net6.0 → net8.0`, or `net7.0 → net9.0`). |
| 75 | +5. Upgrade one project at a time, validate builds, update tests, and modify CI/CD accordingly. |
| 76 | + |
| 77 | +--- |
| 78 | + |
| 79 | +## Auto-Detect Current .NET Version |
| 80 | +To automatically detect the current framework versions across the solution: |
| 81 | + |
| 82 | +```bash |
| 83 | +# 1. Check global SDKs installed |
| 84 | +dotnet --list-sdks |
| 85 | + |
| 86 | +# 2. Detect project-level TargetFrameworks |
| 87 | +find . -name "*.csproj" -exec grep -H "<TargetFramework" {} \; |
| 88 | + |
| 89 | +# 3. Optional: summarize unique framework versions |
| 90 | +grep -r "<TargetFramework" **/*.csproj | sed 's/.*<TargetFramework>//;s/<\/TargetFramework>//' | sort | uniq |
| 91 | + |
| 92 | +# 4. Verify runtime environment |
| 93 | +dotnet --info | grep "Version" |
| 94 | +``` |
| 95 | + |
| 96 | +**Chat Prompt:** |
| 97 | +> "Analyze the repository and list each project’s current TargetFramework along with the latest available LTS version from Microsoft’s release schedule." |
| 98 | +
|
| 99 | +--- |
| 100 | + |
| 101 | +## Discovery & Analysis Commands |
| 102 | +```bash |
| 103 | +# List all projects |
| 104 | +dotnet sln list |
| 105 | + |
| 106 | +# Check current target frameworks for each project |
| 107 | +grep -H "TargetFramework" **/*.csproj |
| 108 | + |
| 109 | +# Check outdated packages |
| 110 | +dotnet list <ProjectName>.csproj package --outdated |
| 111 | + |
| 112 | +# Generate dependency graph |
| 113 | +dotnet msbuild <ProjectName>.csproj /t:GenerateRestoreGraphFile /p:RestoreGraphOutputPath=graph.json |
| 114 | +``` |
| 115 | + |
| 116 | +**Chat Prompt:** |
| 117 | +> "Analyze the solution and summarize each project’s current TargetFramework and suggest the appropriate next LTS upgrade version." |
| 118 | +
|
| 119 | +--- |
| 120 | + |
| 121 | +## Classification Rules |
| 122 | +- `TargetFramework` starts with `netcoreapp`, `net5.0+`, `net6.0+`, etc. → **Modern .NET** |
| 123 | +- `netstandard*` → **.NET Standard** (migrate to current .NET version) |
| 124 | +- `net4*` → **.NET Framework** (migrate via intermediate step to .NET 6+) |
| 125 | + |
| 126 | +--- |
| 127 | + |
| 128 | +## Upgrade Sequence |
| 129 | +1. **Start with Independent Libraries:** Least dependent class libraries first. |
| 130 | +2. **Next:** Shared components and common utilities. |
| 131 | +3. **Then:** API, Web, or Function projects. |
| 132 | +4. **Finally:** Tests, integration points, and pipelines. |
| 133 | + |
| 134 | +**Chat Prompt:** |
| 135 | +> "Generate the optimal upgrade order for this repository, prioritizing least-dependent projects first." |
| 136 | +
|
| 137 | +--- |
| 138 | + |
| 139 | +## Per-Project Upgrade Flow |
| 140 | +1. **Create branch:** `upgrade/<project>-to-<targetVersion>` |
| 141 | +2. **Edit `<TargetFramework>`** in `.csproj` to the suggested version (e.g., `net9.0`) |
| 142 | +3. **Restore & update packages:** |
| 143 | + ```bash |
| 144 | + dotnet restore |
| 145 | + dotnet list package --outdated |
| 146 | + dotnet add package <PackageName> --version <LatestVersion> |
| 147 | + ``` |
| 148 | +4. **Build & test:** |
| 149 | + ```bash |
| 150 | + dotnet build <ProjectName>.csproj |
| 151 | + dotnet test <ProjectName>.Tests.csproj |
| 152 | + ``` |
| 153 | +5. **Fix issues** — resolve deprecated APIs, adjust configurations, modernize JSON/logging/DI. |
| 154 | +6. **Commit & push** PR with test evidence and checklist. |
| 155 | + |
| 156 | +--- |
| 157 | + |
| 158 | +## Breaking Changes & Modernization |
| 159 | +- Use `.NET Upgrade Assistant` for initial recommendations. |
| 160 | +- Apply analyzers to detect obsolete APIs. |
| 161 | +- Replace outdated SDKs (e.g., `Microsoft.Azure.*` → `Azure.*`). |
| 162 | +- Modernize startup logic (`Startup.cs` → `Program.cs` top-level statements). |
| 163 | + |
| 164 | +**Chat Prompt:** |
| 165 | +> "List deprecated or incompatible APIs when upgrading from <currentVersion> to <targetVersion> for <ProjectName>." |
| 166 | +
|
| 167 | +--- |
| 168 | + |
| 169 | +## CI/CD Configuration Updates |
| 170 | +Ensure pipelines use the detected **target version** dynamically: |
| 171 | + |
| 172 | +**Azure DevOps** |
| 173 | +```yaml |
| 174 | +- task: UseDotNet@2 |
| 175 | + inputs: |
| 176 | + packageType: 'sdk' |
| 177 | + version: '$(TargetDotNetVersion).x' |
| 178 | +``` |
| 179 | +
|
| 180 | +**GitHub Actions** |
| 181 | +```yaml |
| 182 | +- uses: actions/setup-dotnet@v4 |
| 183 | + with: |
| 184 | + dotnet-version: '${{ env.TargetDotNetVersion }}.x' |
| 185 | +``` |
| 186 | +
|
| 187 | +--- |
| 188 | +
|
| 189 | +## Validation Checklist |
| 190 | +- [ ] TargetFramework upgraded to next stable version |
| 191 | +- [ ] All NuGet packages compatible and updated |
| 192 | +- [ ] Build and test pipelines succeed locally and in CI |
| 193 | +- [ ] Integration tests pass |
| 194 | +- [ ] Deployed to a lower environment and verified |
| 195 | +
|
| 196 | +--- |
| 197 | +
|
| 198 | +## Branching & Rollback Strategy |
| 199 | +- Use feature branches: `upgrade/<project>-to-<targetVersion>` |
| 200 | +- Commit frequently and keep changes atomic |
| 201 | +- If CI fails after merge, revert PR and isolate failing modules |
| 202 | + |
| 203 | +**Chat Prompt:** |
| 204 | +> "Suggest a rollback and validation plan if the .NET upgrade for <ProjectName> introduces build or runtime regressions." |
| 205 | + |
| 206 | +--- |
| 207 | + |
| 208 | +## Automation & Scaling |
| 209 | +- Automate upgrade detection with GitHub Actions or Azure Pipelines. |
| 210 | +- Schedule nightly runs to check for new .NET releases via `dotnet --list-sdks`. |
| 211 | +- Use agents to automatically raise PRs for outdated frameworks. |
| 212 | + |
| 213 | +--- |
| 214 | + |
| 215 | +## Chatmode Prompt Library |
| 216 | +1. "List all projects with current and recommended .NET versions." |
| 217 | +2. "Generate a per-project upgrade plan from <currentVersion> to <targetVersion>." |
| 218 | +3. "Suggest .csproj and pipeline edits to upgrade <ProjectName>." |
| 219 | +4. "Summarize build/test results post-upgrade for <ProjectName>." |
| 220 | +5. "Create PR description and checklist for the upgrade." |
| 221 | + |
| 222 | +--- |
0 commit comments