Skip to content

KTSU0008 never fires for net8.0 (the SDK's lowest default TFM), and on net8.0 advises pinning System.Collections.Immutable to 1.4.0: it reads the stale PackageOverrides.txt #69

Open

Description

@matt-edmondson

What's wrong

_KtsuGenerateFrameworkOverrideInputs in Sdk/Sdk.targets (~L266-310) feeds FrameworkOverridingPackageAnalyzer (KTSU0008) with @(PackageConflictOverrides->'%(OverriddenPackages)'). That is the targeting pack's PackageOverrides.txt, which the analyzer treats as "the packages and versions this framework ships". Before .NET 9 that file is badly incomplete and out of date.

Microsoft.NETCore.App.Ref 8.0.31's PackageOverrides.txt:

  • has no entry for System.Text.Json, System.Memory or System.IO.Pipelines, although net8.0 ships all three
  • lists System.Collections.Immutable|1.4.0 and System.Reflection.Metadata|1.5.0, although net8.0 ships 8.0 versions of both

The 9.0.x pack does list System.Text.Json|9.0.x, which is why the shipped example (examples/analyzers/KTSU0008-FrameworkOverridingPackage, which targets only net10.0;net9.0) passes.

Failure scenarios

These were reproduced by building Sdk.Analyzers at bafee81 and wiring the real target plus the analyzer DLL into a plain SDK project targeting net10.0;net9.0;net8.0. The per-TFM ktsu.framework-*.g.txt inputs and the diagnostics were then inspected.

A. Missed error, which is the case the rule exists for (#44). A library multi-targeting net10.0;net9.0;net8.0 references System.Text.Json privately (PrivateAssets="all").

  • At 10.0.2, KTSU0008 fires only for net9.0 and says "pin the version to 9.0.x". Following that advice still leaves net8.0 compiled against a 9.0 assembly.
  • At 9.0.0, nothing fires at all.

In both cases the net8.0 build compiles against a higher System.Text.Json than .NET 8 ships, so net8.0 consumers hit FileNotFoundException at runtime. The analyzer's own remarks (L46) say the lowest-supported framework is the one that fires. Here it is the one that never fires.

B. Wrong advice. A private System.Collections.Immutable 9.0.0 reference on net8.0 reports "overriding the 1.4.0 … pin the version to 1.4.0". The code fix would write 1.4.0 into Directory.Packages.props, which is a real downgrade.

Suggested fix

Take framework-provided versions from the SDK's package-pruning data instead of PackageConflictOverrides. @(PrunePackageReference), which CollectPrunePackageReferences populates, lists System.Text.Json and System.Collections.Immutable at 8.0.32767 for net8.0. Alternatively, compare against the assembly versions of the framework reference assemblies. Either source reflects what the framework actually ships.

Acceptance:

  • Add a net8.0 leg to the KTSU0008 example/test.
  • A private System.Text.Json 9.x/10.x reference raises KTSU0008 for net8.0 and suggests an 8.0.x pin.
  • A private System.Collections.Immutable reference no longer suggests 1.4.0.

Activity

  1. added
    bug
    on Sep 30, 2026
  2. matt-edmondson commented on Sep 30, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

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

    analyzersbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions