Skip to content

Commit 7e3aadc

Browse files
author
Cam Soper
authored
[Breaking change]: NU1510 is raised for direct references pruned by NuGet (#45508)
* [Breaking change]: NU1510 is raised for direct references pruned by NuGet Fixes #45462 * lint
1 parent d561264 commit 7e3aadc

File tree

3 files changed

+62
-5
lines changed

3 files changed

+62
-5
lines changed

docs/core/compatibility/10.0.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Breaking changes in .NET 10
33
titleSuffix: ""
44
description: Navigate to the breaking changes in .NET 10.
5-
ms.date: 01/30/2025
5+
ms.date: 03/25/2025
66
ai-usage: ai-assisted
77
no-loc: [Blazor, Razor, Kestrel]
88
---
@@ -49,10 +49,11 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af
4949

5050
## SDK
5151

52-
| Title | Type of change | Introduced version |
53-
|----------------------------------------------------------------------------------------------------------------------|-------------------|--------------------|
54-
| [Default workload configuration from 'loose manifests' to 'workload sets' mode](sdk/10.0/default-workload-config.md) | Behavioral change | Preview 2 |
55-
| [MSBUILDCUSTOMBUILDEVENTWARNING escape hatch removed](sdk/10.0/custom-build-event-warning.md) | Behavioral change | Preview 1 |
52+
| Title | Type of change | Introduced version |
53+
|----------------------------------------------------------------------------------------------------------------------|---------------------|--------------------|
54+
| [Default workload configuration from 'loose manifests' to 'workload sets' mode](sdk/10.0/default-workload-config.md) | Behavioral change | Preview 2 |
55+
| [MSBUILDCUSTOMBUILDEVENTWARNING escape hatch removed](sdk/10.0/custom-build-event-warning.md) | Behavioral change | Preview 1 |
56+
| [NU1510 is raised for direct references pruned by NuGet](sdk/10.0/nu1510-pruned-references.md) | Source incompatible | Preview 1 |
5657

5758
## Windows Forms
5859

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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.

docs/core/compatibility/toc.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ items:
4646
href: sdk/10.0/default-workload-config.md
4747
- name: MSBUILDCUSTOMBUILDEVENTWARNING escape hatch removed
4848
href: sdk/10.0/custom-build-event-warning.md
49+
- name: NU1510 is raised for direct references pruned by NuGet
50+
href: sdk/10.0/nu1510-pruned-references.md
4951
- name: Windows Forms
5052
items:
5153
- name: API obsoletions
@@ -1908,6 +1910,8 @@ items:
19081910
href: sdk/10.0/default-workload-config.md
19091911
- name: MSBUILDCUSTOMBUILDEVENTWARNING escape hatch removed
19101912
href: sdk/10.0/custom-build-event-warning.md
1913+
- name: NU1510 is raised for direct references pruned by NuGet
1914+
href: sdk/10.0/nu1510-pruned-references.md
19111915
- name: .NET 9
19121916
items:
19131917
- name: "`dotnet restore` audits transitive packages"

0 commit comments

Comments
 (0)