Skip to content

[Breaking change]: PackageReference without a version will raise an error #46386

Open
@zivkan

Description

@zivkan

Description

PackageReference validation is being improved to give clearer and more actionable messages when the version metadata is missing.

There's no change when using Central Package Management, since by design the PackageReference XML should not have a version.

PR implementing the change:

Version

.NET 10 Preview 6

Previous behavior

NuGet will raise a NU1604 warning, with text "Project dependency 'PackageA' does not contain an inclusive lower bound. Include a lower bound in the dependency version to ensure consistent restore results."

New behavior

NuGet will raise a NU1015 error with text "The following PackageReference item(s) do not have a version specified: PackageA"

Type of breaking change

  • Binary incompatible: Existing binaries might encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
  • Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code might require source changes to compile successfully.
  • Behavioral change: Existing binaries might behave differently at run time.

Reason for change

The "no lower bound" message is confusing, and it's unclear how to fix the issue. Additionally, NuGet would end up restoring the lowest version for that package, which is rarely what developers want.version

Recommended action

Add a version to the package reference, for example:

- <PackageReference Include="Some.Package" />
+ <PackageReference Include="Some.Package" Version="1.2.3" />

If the lowest package version is desired, then use Version="0.0.0". In this case, NuGet will raise warning NU1603, rather than the previous NU1604.

SdkAnalysisLevel can be set to 9.0.300 or lower, and NuGet will revert to the previous warning. However, this will affect all features that gate on SdkAnalysisLevel.

Feature area

SDK

Affected APIs

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

🔖 Ready

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions