Repository navigation
Description
What
TransitivePackageUsedDirectlyCodeFixProvider resolves KTSU0006 by adding a PackageReference (and, under central package management, a PackageVersion) at the version the analyzer observed:
// TransitivePackageUsedDirectlyCodeFixProvider.cs:82
string? versionForReference = centrallyManaged ? null : packageVersion;For a package that also ships in the shared framework — System.Text.Json, System.Memory, and friends — that fix can produce a library that throws FileNotFoundException for every consumer on a lower target framework, and nothing in the build says so.
The mechanism
ktsu-dev/GitIntegration hit this and documented it at length. Adding
<PackageReference Include="System.Text.Json" PrivateAssets="all" />to a project multi-targeting net10.0;net9.0 resolved the package's real 10.0.2 assembly on net9.0, overriding that framework's own 9.0.x copy. PrivateAssets="all" correctly kept the package out of the nupkg — so the consumer resolves nothing, runs on a 9.0.x shared framework carrying System.Text.Json 9.0.0.0, and meets a compiled reference to 10.0.0.0. CoreCLR rolls assembly binds forward but never backward.
The failure is invisible in the producing repo's build and in its nuspec. It only appears when something consumes the packed artifact.
Why an analyzer is the right home for this
This is a hazard the SDK's own analyzer creates. KTSU0006 demands the reference; the fixer writes it; nothing then checks whether the reference is safe. Two repositories have now had to work it out by hand, and the check that catches it is mechanical:
Read
obj/<TargetFramework>/project.assets.jsonand look at what the reference resolves for itscompileasset.
"compile": { "lib/net9.0/_._": {} }— an empty placeholder — means the framework wins and the reference is safe.- A real assembly path (
"lib/net9.0/System.Text.Json.dll") means the package is overriding the framework, and the version must be pinned to what the lowest-supported target framework ships.
Sdk/Sdk.targets already computes package-graph facts and hands them to KTSU0005/KTSU0006 as AdditionalFiles (orphan list, assembly→package map, direct-package set). The same target has everything it needs to emit a fourth input: for each direct PackageReference, whether its compile asset is a placeholder or a real assembly, per target framework.
Proposal
A new diagnostic (KTSU0008) — "package reference overrides the shared framework". Reported when a direct PackageReference resolves a real compile asset on a target framework whose shared framework also supplies that assembly, and the pinned version is above what the lowest-supported framework ships.
A code fix that pins the PackageVersion down to the floor, and adds NoWarn="NU1510" on the item — NuGet's package-pruning warning fires in exactly this situation and says the opposite of what KTSU0006 says, so both diagnostics can only be satisfied together with that scoped suppression. GitIntegration's fix is the worked example: pin System.Text.Json centrally to 9.0.13, NoWarn="NU1510" on the reference.
Failing that, at minimum: make the KTSU0006 fixer add PrivateAssets="all" and emit the check as a comment or a build warning, so the person taking the fix is told there is a second question to answer.
Related
- The neighbouring hazard — another package in the graph pinning a lower version than CPM floats, needing
VersionOverride— is the same class of bug from a different direction (GitIntegration'sTestably.Abstractions.FileSystem.Interfacecase). If the analyzer reads the resolved graph anyway, both are detectable from the same data. - KTSU0007 already enforces
PrivateAssetsforPolyfillonly; a reference added by the KTSU0006 fixer is not covered by it.
Activity
matt-edmondson commentedon Sep 10, 2026
Triage: Priority: High · Effort: Medium
KTSU0006's code fix can pin a
PackageReference/PackageVersionabove what a lower target framework's shared framework ships, producing a package that throwsFileNotFoundExceptionfor every consumer on that framework — invisible in the producing repo's own build and nuspec. This has already bitten GitIntegration in practice and is a hazard the SDK's own analyzer creates, so it belongs in the SDK rather than being rediscovered per-repo.Suggested next steps / acceptance criteria:
Sdk/Sdk.targets, alongside the KTSU0005/KTSU0006 inputs) to emit, per directPackageReference, whether itscompileasset resolves to a framework placeholder or a real assembly per target frameworkNoWarn="NU1510"on the item (NuGet's pruning warning says the opposite of KTSU0006 in exactly this case)PrivateAssets="all"and surface theproject.assets.jsoncheck as guidance so the person taking the fix knows there's a second question to answerSystem.Text.Json)Blockers/dependencies: none; related to KTSU0007 (currently Polyfill-only
PrivateAssetsenforcement) and to the neighboringVersionOverridehazard noted in the issue, which could share the same resolved-graph data if tackled togetherGenerated by Claude Code
matt-edmondson commentedon Sep 13, 2026
Triage
Category: Bug
Priority: High
Suggested assignment: none — already in
sdk(the repo whose own analyzer/code-fix creates the hazard); no other repo is implicatedPossible duplicate: none found — no other open Sdk issue covers the KTSU0006 fixer or a framework-override diagnostic
Generated by Claude Code
matt-edmondson commentedon Sep 13, 2026
Note for anyone reading this thread: the
**Triage:**comment above and the## Triagecomment below both cover this same finding — they were posted by two different automation routines (an issue-creation/review routine and the org-wide issue-triage routine) that didn't recognize each other's comment format. That gap has since been fixed so it won't recur. No action needed here; treat the two as complementary (the first has the detailed acceptance criteria, the second has the org-wide classification).Generated by Claude Code
matt-edmondson commentedon Sep 22, 2026
Implemented in #50 as KTSU0008, with the analyzer, the code fix, and the
Sdk.targetsinput generation the issue sketches. Two things measured along the way are worth recording here, because both changed the shape of what landed.The mechanism, confirmed rather than assumed
Built a
net10.0;net9.0project referencingSystem.Text.Json10.0.2 and read back what each inner build resolved:compileasset forSystem.Text.Jsonnet10.0net9.0lib/net9.0/System.Text.Json.dllBuild succeeded. 0 Error(s), exactly as the issue says. So theproject.assets.jsoncheck the issue describes is real, and it has a cheaper source than parsing that file:@(ResolvedCompileFileDefinitions)already carries the resolved assembly with itsNuGetPackageId, and@(PackageConflictOverrides)'OverriddenPackagesmetadata is the targeting pack'sPackageOverrides.txt. Both are per-target-framework MSBuild state available afterResolveReferences, so no file parsing is needed and "the lowest supported framework" falls out for free — the inner build that has the problem is the one that reports.NU1510 is not the safety net it looks like
Worth knowing, because it is the reason this rule earns its place rather than duplicating NuGet. The first version of the triggering example failed at restore, before the compiler ran:
NU1510 fires for any reference to a framework-supplied package — the safe pinned-to-the-floor version and the dangerous higher one alike. It does not compare versions. Combined with this SDK treating warnings as errors, that means a project KTSU0006 has told to declare the reference has no choice but to
NoWarnit, which is the state GitIntegration's fix ended up in. Once silenced, nothing checks the version at all — which is precisely the gap. The example therefore carriesNoWarn="NU1510"; without it the scenario never reaches the analyzer and the test would be a straw man.One deliberate narrowing, for you to confirm
The proposal conditions on override + version above the floor. The implementation adds a third condition: the reference must be fully private.
NuGet omits a dependency from the produced package only when every asset kind is private, and it is that omission which leaves the consumer resolving nothing and falling back to the framework's lower copy. A reference that still flows carries the higher version to the consumer and resolves there — unusual, but not broken. At
Errorseverity, firing on it would fail builds across the organization for working code, so it is excluded.That matches GitIntegration's actual case (
PrivateAssets="all") and the spirit of KTSU0007, which is also why "fully private" moved into a shared helper both analyzers now read instead of being spelled out twice. If you want the wider rule the issue literally describes, it is a one-line change — your call, and the easiest thing to settle in review.Not done here
The neighbouring
VersionOverridehazard from the Related section is not covered. It is detectable from the same data, but it is a different diagnostic with a different fix, and bundling it would have made this PR two rules instead of one. Happy to take it as a follow-up if it is wanted.Generated by Claude Code