Repository navigation
Description
Problem
On a host with both the .NET 10 and .NET 11 SDKs installed, the pre-commit hook's .NET Format task fails and blocks every commit. CI is unaffected, since the hub's validator installs dotnet-version: 10.x.
global.json pins no SDK (it only sets the Microsoft.Testing.Platform runner), so the dotnet host selects the newest installed SDK, 11.0.100. Directory.Build.props sets AnalysisLevel to latest-all and LangVersion to latest, so the analyzer rule set and language version move with whichever SDK is selected. Under SDK 11, dotnet format style --verify-no-changes --severity=info loads analysislevel_11_all.globalconfig and reports IDE0028 ("Collection initialization can be simplified") at 7 existing sites:
PhotoCleaner/CommandLine.cs:47PhotoCleaner/ImportTask.cs:477PhotoCleaner/VerifyTask.cs:103,:191,:260PhotoCleaner/UndoTask.cs:35,:60
The same command under SDK 10.0.404 passes. The task writes nothing, so the tree is unchanged after the failure.
Reproduce
- Install the .NET 11 SDK alongside .NET 10.
- In a fresh checkout, run
dotnet tool restoreanddotnet husky install. - Commit any change. The
.NET Formattask fails with the IDE0028 lines above.
Not yet checked under SDK 11: the full clean-compile chain (CSharpier, then dotnet build with TreatWarningsAsErrors) and dotnet test. Run those as part of the fix, since a newer analysis level can add build warnings too.
Expected
The repository builds, formats, and tests cleanly under both the .NET 10 and the .NET 11 SDK, by configuration rather than by which SDK a host happens to have. Local hooks and CI then agree.
Options to Weigh
- Pin the SDK in
global.json(sdk.versionwith arollForwardpolicy). This makes a host select 10, but a host with only 11 would fail or roll forward depending on the policy, and it does not make the code clean under 11. - Pin
AnalysisLevelto a fixed version rather thanlatest-all, so the rule set stops floating with the SDK, and raise it deliberately. - Fix the 7 sites so the code satisfies both analysis levels, if the simplified form compiles and passes the SDK 10 rules too.
- A combination, plus making CI exercise the newer SDK so drift shows up in a pull request rather than on a developer's machine.
The fleet code style for Directory.Build.props and analyzer configuration is in the dotnet-codestyle Skill. A config-level choice that should hold fleet-wide belongs in the hub.
Interim Workaround
Commit with a temporary, unstaged global.json that adds "sdk": {"version": "10.0.404", "rollForward": "latestFeature"}, then restore it with git checkout -- global.json. That runs the hook under the SDK CI uses. Found during the hub resync in #261.
🤖 Generated with Claude Code
Activity
Select the .NET SDK 10 Line and Tie the C# Version to the TFM (#263)