.NET 10 NU1015: Fix PackageReference Without Version Restore Failures
.NET 10 NU1015 turns a PackageReference without a version into a restore error. I like the stricter default because an unbounded direct dependency can quietly resolve the lowest package version. The catch is that versionless XML is also the correct shape for NuGet Central Package Management (CPM). A mechanical “add Version everywhere” repair can undo the policy your repository intended to…
.NET 10 NU1015 introduces a strict rule that requires specifying a version for direct PackageReference entries in project files. Previously, NuGet would allow versionless references, which could resolve to the lowest available package version. With the release of .NET 10, this behavior has changed, and restore operations will now fail when encountering versionless direct references.
This change can be problematic for repositories that rely on NuGet Central Package Management (CPM), where versionless references are the correct format. The issue arises when a project is copied into a location where CPM is either disabled or the repository's props file is no longer discovered. In such cases, the NU1015 diagnostic is triggered, pointing to a potential problem with the project file or repository-level package policy.
To resolve this issue, developers should decide who owns the version - either the direct reference or the CPM file - and ensure that the restore process can verify the resolution. This can be achieved by either adding a version to direct references or keeping the reference versionless and specifying the version in the nearest Directory.Packages.props file.
The NuGet documentation provides guidance on both approaches, emphasizing the importance of determinism in the restore process. The provided sample demonstrates the two valid outcomes and how to reproduce the NU1015 error using a local package feed. It also highlights the importance of avoiding the use of the SdkAnalysisLevel switch for this specific diagnostic, as it can have unintended consequences on other SDK behaviors.
In summary, .NET 10 NU1015 enforces a stricter versioning policy for direct PackageReference entries, requiring developers to explicitly specify a version or rely on version management in the nearest Directory.Packages.props file. Properly addressing this issue ensures a smooth restore process and avoids unintentional changes to the repository's package management.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.