Skip to content

Make the Build, Format, and Test Chain Clean Under Both .NET 10 and .NET 11 SDKs #262

Closed

Description

@ptr727

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:47
  • PhotoCleaner/ImportTask.cs:477
  • PhotoCleaner/VerifyTask.cs:103, :191, :260
  • PhotoCleaner/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

  1. Install the .NET 11 SDK alongside .NET 10.
  2. In a fresh checkout, run dotnet tool restore and dotnet husky install.
  3. Commit any change. The .NET Format task 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.version with a rollForward policy). 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 AnalysisLevel to a fixed version rather than latest-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

  1. added
    bug
    .NET
    on Nov 12, 2026
  2. added a commit that references this issue on Nov 12, 2026
    2609681
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions