|
| 1 | +--- |
| 2 | +title: "Breaking change - NU1510 is raised for direct references pruned by NuGet" |
| 3 | +description: "Learn about the breaking change in .NET 10 where NU1510 is raised for unnecessary direct package references." |
| 4 | +ms.date: 3/25/2025 |
| 5 | +ai-usage: ai-assisted |
| 6 | +ms.custom: https://github.com/dotnet/docs/issues/45462 |
| 7 | +--- |
| 8 | + |
| 9 | +# NU1510 is raised for direct references pruned by NuGet |
| 10 | + |
| 11 | +Starting in .NET 10, NuGet raises a [`NU1510` warning](/nuget/reference/errors-and-warnings/nu1510) when a project includes a direct package reference that overlaps with a framework-provided library and is not required. |
| 12 | + |
| 13 | +## Version introduced |
| 14 | + |
| 15 | +.NET 10 Preview 1 |
| 16 | + |
| 17 | +## Previous behavior |
| 18 | + |
| 19 | +Previously, the .NET SDK ignored the contents of a package if it overlapped with a framework-provided library. The package reference was allowed but had no effect on the build output. |
| 20 | + |
| 21 | +## New behavior |
| 22 | + |
| 23 | +NuGet now removes unnecessary package references entirely and raises a `NU1510` warning to notify you of the issue. |
| 24 | + |
| 25 | +## Type of breaking change |
| 26 | + |
| 27 | +This is a [source-incompatible change](../../categories.md#source-compatibility). |
| 28 | + |
| 29 | +## Reason for change |
| 30 | + |
| 31 | +This change reduces the maintenance burden on developers by eliminating unused package references. It prevents unnecessary updates, reduces download and restore times, and ensures cleaner build artifacts. The [`NU1510` warning](/nuget/reference/errors-and-warnings/nu1510) warning helps you identify and clean up these references proactively. |
| 32 | + |
| 33 | +## Recommended action |
| 34 | + |
| 35 | +If your project targets only frameworks where the package is pruned, remove the package reference entirely. For multi-targeting projects, conditionally include the package reference only for frameworks that require it. Use the following example as a guide: |
| 36 | + |
| 37 | +```xml |
| 38 | +<ItemGroup> |
| 39 | + <!-- reference 8.0 System.Text.Json when targeting things older than .NET 8 --> |
| 40 | + <PackageReference Include="System.Text.Json" Version="8.0.5" Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))" /> |
| 41 | + |
| 42 | + <!-- reference 10.0 System.Linq.AsyncEnumerable when targeting things older than .NET 10 --> |
| 43 | + <PackageReference Include="System.Linq.AsyncEnumerable" Version="10.0.0-preview.2.25163.2" Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net.10'))" /> |
| 44 | + |
| 45 | + <!-- Reference System.Memory on frameworks not compatible with .NET Core 2.1 nor .NETStandard 2.1 --> |
| 46 | + <PackageReference Include="System.Memory" Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'netcoreapp2.1')) and !$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'netstandard2.1'))" /> |
| 47 | +</ItemGroup> |
| 48 | +``` |
| 49 | + |
| 50 | +## Affected APIs |
| 51 | + |
| 52 | +None. |
0 commit comments