Skip to content

Commit c778bcb

Browse files
authored
Clarify NU1510 documentation (#3521)
1 parent 37b5cc5 commit c778bcb

1 file changed

Lines changed: 17 additions & 25 deletions

File tree

docs/reference/errors-and-warnings/NU1510.md

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,68 +17,60 @@ f1_keywords:
1717
1818
### Issue
1919

20-
The package `System.Text.Json` has been specified for pruning through the [PrunePackageReference](../../consume-packages/Package-References-in-Project-Files.md#prunepackagereference) feature.
21-
The `.NET SDK` generally specifies the list of packages to be pruned. The package is not needed as a direct PackageReference since the .NET runtime itself carries either the same or higher version of the assembly.
20+
This warning is raised as a result of NuGet dependency graph pruning, and indicates that an otherwise prunable package was restored due to a direct `PackageReference`.
21+
The named package can be pruned if the direct `PackageReference` is removed, since the targeted .NET SDK provides the same version or higher of this assembly.
2222

23-
This warning is *only* raised when the PackageReference in question *can be completely removed from the project*.
23+
This warning only affects packages registered for pruning through the [PrunePackageReference](../../consume-packages/Package-References-in-Project-Files.md#prunepackagereference) feature.
24+
It is *only* raised when the `PackageReference` in question *can be completely removed from the project*.
2425

2526
#### Example 1
2627

28+
When the targeted .NET SDK includes an equivalent version, *dependency conflict resolution* selects the SDK-bundled assembly:
29+
2730
```xml
2831
<PropertyGroup>
32+
<!-- 'System.Text.Json' is SDK-bundled in 'net10.0' -->
2933
<TargetFramework>net10.0</TargetFramework>
3034
</PropertyGroup>
3135

3236
<ItemGroup>
37+
<!-- The assembly provided by this reference will not be used -->
3338
<PackageReference Include="System.Text.Json" Version="10.0.0" />
3439
</ItemGroup>
3540
```
3641

3742
#### Example 2
3843

39-
```xml
40-
<PropertyGroup>
41-
<TargetFrameworks>net9.0;net10.0</TargetFrameworks>
42-
</PropertyGroup>
43-
44-
<ItemGroup>
45-
<PackageReference Condition="'$(TargetFramework)' == 'net10.0'" Include="System.Text.Json" Version="10.0.0" />
46-
<PackageReference Condition="'$(TargetFramework)' == 'net9.0'" Include="System.Text.Json" Version="9.0.0" />
47-
</ItemGroup>
48-
```
49-
50-
Each conditional `PackageReference` for the `System.Text.Json` package can be removed because the package is already included in the respective .NET runtime versions for the frameworks it is declared for.
51-
52-
#### Example 3
44+
When the targeted .NET SDK includes an equivalent version for multiple framework targets, *dependency conflict resolution* selects the appropriate SDK-bundled assembly for each target:
5345

5446
```xml
5547
<PropertyGroup>
48+
<!-- 'System.Text.Json' is SDK-bundled in both TFMs -->
5649
<TargetFrameworks>net9.0;net10.0</TargetFrameworks>
5750
</PropertyGroup>
5851

5952
<ItemGroup>
60-
<PackageReference Condition="'$(TargetFramework)' == 'net9.0'" Include="System.Text.Json" Version="9.0.4" />
53+
<!-- Neither of the assemblies provided by these references will be used -->
54+
<PackageReference Include="System.Text.Json" Version="10.0.0" Condition="'$(TargetFramework)' == 'net10.0'"/>
55+
<PackageReference Include="System.Text.Json" Version="9.0.4" Condition="'$(TargetFramework)' == 'net9.0'"/>
6156
</ItemGroup>
6257
```
6358

64-
The `System.Text.Json` package is within the pruning range of the only framework it's declared for.
65-
6659
### Solution
6760

68-
Remove the PackageReference as it's unnecessary.
69-
70-
> [!NOTE]
71-
> In order to allow for easier adoption of the PrunePackageReference feature, this warning is raised by default when a project targets the .NET 10 framework or newer.
61+
Remove the unnecessary `PackageReference`.
7262

7363
> [!NOTE]
74-
> The warning will not be raised in scenarios in which at least one of the frameworks still needs the package, such as `net48` in the below example.
64+
> Beginning with .NET 10, the `PrunePackageReference` feature is enabled by default for all projects that target .NET 10 or higher. The warning is only raised when pruning applies to all runtime targets:
7565
>
7666
> ```xml
7767
> <PropertyGroup>
68+
> <!-- 'System.Text.Json' is not SDK-bundled in 'net48' -->
7869
> <TargetFrameworks>net10.0;net48</TargetFrameworks>
7970
> </PropertyGroup>
8071
>
8172
> <ItemGroup>
73+
> <!-- This reference is needed in 'net48' - NU1510 is not raised -->
8274
> <PackageReference Include="System.Text.Json" Version="9.0.7" />
8375
> </ItemGroup>
8476
> ```

0 commit comments

Comments
 (0)