|
| 1 | +# NuGet Package Maintenance |
| 2 | + |
| 3 | +The repository targets both `net9.0` and `net10.0`, so dependency updates must keep the two TFMs in sync. This page captures the automation that already exists and the non-standard manual process that can be used when Dependabot cannot unblock an update quickly enough. |
| 4 | + |
| 5 | +## Default Path: Dependabot |
| 6 | + |
| 7 | +- `.github/dependabot.yml` schedules daily `nuget` scans over `src/`, so each library receives upgrade PRs automatically. |
| 8 | +- Accept Dependabot PRs whenever possible. They already run the full CI matrix, ensuring `net9.0`/`net10.0` builds remain healthy. |
| 9 | +- If a dependency requires coordination across multiple repositories or needs additional context (e.g., SDK preview alignment), leave the manual flow below as a last resort and document the rationale in the PR. |
| 10 | + |
| 11 | +## Non-Standard Manual Script |
| 12 | + |
| 13 | +Only run the script when you need an expedited update outside Dependabot’s cadence (e.g., urgent security patch or coordinating a batch upgrade). |
| 14 | + |
| 15 | +- **VS Code task (recommended):** `Terminal → Run Task… → update-nuget-packages`. This task shells into PowerShell, invokes the script with execution policy bypassed, and streams the build/test output in the integrated terminal. |
| 16 | +- **Direct PowerShell:** `pwsh ./scripts/update-nuget-packages.ps1` |
| 17 | + |
| 18 | +What the script does: |
| 19 | + |
| 20 | +1. Restores the local `.config/dotnet-tools.json` manifest and installs `dotnet-outdated-tool`. |
| 21 | +2. Executes `dotnet-outdated --upgrade` against `src/MX.Api.Abstractions.sln`, ensuring both target frameworks receive the same versions (the tool does not touch lock files; this repo relies on PackageReference flow only). Any tool failure stops the script immediately so you can resolve TFM-specific issues before proceeding. |
| 22 | +3. Builds and tests the solution (skipping `IntegrationTests`) so regressions in either `net9.0` or `net10.0` are caught immediately. |
| 23 | + |
| 24 | +### Optional Parameters |
| 25 | + |
| 26 | +- `-VersionLock <None|Major|Minor>` – default `Major`; stay within the current major line for shared dependencies unless you intentionally want cross-major upgrades (`None`). |
| 27 | +- `-IncludePrerelease` – allow preview packages (useful when the SDK is on a preview track). |
| 28 | +- `-IncludeTransitive` – also upgrade transitive dependencies when the solution depends on them indirectly. |
| 29 | +- `-SkipVerification` – avoid the build/test phase (only when another pipeline will run immediately). When using the VS Code task, pass extra switches by editing `.vscode/tasks.json` or running the script directly. |
| 30 | + |
| 31 | +### Manual Command Output |
| 32 | + |
| 33 | +The script updates project files in-place; review the diffs locally and open a single PR that summarizes the context (why Dependabot was bypassed, verification performed, etc.). Always follow up with the standard `dotnet build` / `dotnet test` tasks if you skipped verification. |
| 34 | + |
| 35 | +## Framework-specific packages |
| 36 | + |
| 37 | +Some dependencies publish different major versions per TFM (e.g., ASP.NET test host packages). Use conditional `ItemGroup` blocks to pin the correct line for each target framework: |
| 38 | + |
| 39 | +```xml |
| 40 | +<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'"> |
| 41 | + <PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.11" /> |
| 42 | +</ItemGroup> |
| 43 | +<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'"> |
| 44 | + <PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.0" /> |
| 45 | +</ItemGroup> |
| 46 | +``` |
| 47 | + |
| 48 | +- Dependabot and `dotnet-outdated` evaluate each block independently, so they still surface upgrades within the respective major line. |
| 49 | +- Keep shared dependencies (xUnit, Moq, etc.) in the unconditional `ItemGroup`; only split packages that genuinely need divergent versions. |
| 50 | +- When onboarding a new TFM, duplicate the conditional block and set the appropriate version before running the script or Dependabot. |
0 commit comments