Skip to content

Restore fails with NU1013 in every non-test project when a repo sets CentralPackageVersionOverrideEnabled=false: the SDK's implicit ktsu.Sdk.Analyzers reference uses VersionOverride #105

Open

Description

@matt-edmondson

What's wrong

Sdk/Sdk.targets:314 injects the analyzer like this:

<PackageReference Include="ktsu.Sdk.Analyzers" VersionOverride="{version}" Condition="$(IsTestProject) == 'false'">

NuGet documents CentralPackageVersionOverrideEnabled=false as the Central Package Management switch that forbids VersionOverride, so that every version comes from Directory.Packages.props. When a repository turns it on, the SDK's own implicit reference breaks restore.

Repro

Enable CPM and add <CentralPackageVersionOverrideEnabled>false</CentralPackageVersionOverrideEnabled> to Directory.Packages.props in a ktsu.Sdk library repo, then run dotnet build:

error NU1013: The following PackageReference items cannot specify a value for VersionOverride: ktsu.Sdk.Analyzers.

The consumer can't work around it short of turning the hardening switch back off. A PackageVersion entry for ktsu.Sdk.Analyzers doesn't help, because the item still carries VersionOverride.

Fix verified locally: with the cached Sdk.targets edited to <PackageReference Include="ktsu.Sdk.Analyzers" Version="{version}" IsImplicitlyDefined="true" …>, restore and build succeed with overrides disabled, and also with CPM in its default state. CPM off already works today.

Suggested fix / acceptance criteria

  • Reference the analyzer with Version="{version}" plus IsImplicitlyDefined="true". That is how the .NET SDK adds its own implicit packages under CPM, and NuGet then skips the central-version requirement.
  • Add a regression example or test that sets CentralPackageVersionOverrideEnabled=false and builds.
  • Make sure KTSU0005 (orphaned PackageVersion) and KTSU0008 still behave as before for that item.

Activity

  1. added
    bug
    on Nov 5, 2026
  2. matt-edmondson commented on Nov 5, 2026

    @matt-edmondson
    ContributorAuthor

    Triage

    • Category: Bug
    • Priority: Medium. It only hits repos that opt into the CentralPackageVersionOverrideEnabled=false hardening switch, but those repos have no workaround short of turning the switch off. The fix is small and already verified locally.
    • Area: Sdk.targets implicit analyzer reference
    • Suggested assignment: SDK core / analyzers owner
    • Duplicates / related: not a duplicate. Related to KTSU0008 code fix ignores VersionOverride: the diagnostic never clears and the fix only adds NoWarn="NU1510" #77, where KTSU0008's code fix ignores VersionOverride, so check KTSU0005 and KTSU0008 together when switching to IsImplicitlyDefined.
    • In progress: no open PR

    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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions