|
| 1 | +--- |
| 2 | +title: "Breaking change - PrunePackageReference marks direct prunable references with PrivateAssets=all and IncludeAssets=none" |
| 3 | +description: "Learn about the breaking change in the .NET 10 SDK where PrunePackageReference automatically marks directly prunable PackageReference with PrivateAssets=all and IncludeAssets=none." |
| 4 | +ms.date: 01/03/2025 |
| 5 | +ai-usage: ai-assisted |
| 6 | +--- |
| 7 | + |
| 8 | +# PrunePackageReference marks direct prunable references with PrivateAssets=all and IncludeAssets=none |
| 9 | + |
| 10 | +The [PrunePackageReference](/nuget/consume-packages/package-references-in-project-files#prunepackagereference) feature automatically removes *transitive* packages that are provided by the target platform. With this change, the feature also marks *directly* prunable `PackageReference` items with `PrivateAssets=all` and `IncludeAssets=none` attributes. These attributes prevent the packages from appearing in generated dependency lists for packages. |
| 11 | + |
| 12 | +## Version introduced |
| 13 | + |
| 14 | +.NET 10 Preview 7 |
| 15 | + |
| 16 | +## Previous behavior |
| 17 | + |
| 18 | +In earlier .NET 10 previews, directly prunable `PackageReference` items might have generated an [`NU1510` warning](/nuget/reference/errors-and-warnings/nu1510) but still appeared in the generated *.nuspec* dependencies for all target frameworks, even those where the package is provided by the platform. |
| 19 | + |
| 20 | +For example, consider a multi-targeting project with the following configuration: |
| 21 | + |
| 22 | +```xml |
| 23 | +<PropertyGroup> |
| 24 | + <TargetFramework>net9.0;net472</TargetFramework> |
| 25 | +</PropertyGroup> |
| 26 | + |
| 27 | +<ItemGroup> |
| 28 | + <PackageReference Include="System.Text.Json" Version="9.0.4" /> |
| 29 | +</ItemGroup> |
| 30 | +``` |
| 31 | + |
| 32 | +Such a project file generated a *.nuspec* file with dependencies for both target frameworks: |
| 33 | + |
| 34 | +```xml |
| 35 | +<dependencies> |
| 36 | + <group targetFramework=".NETFramework4.7.2"> |
| 37 | + <dependency id="System.Text.Json" version="9.0.4" /> |
| 38 | + </group> |
| 39 | + <group targetFramework="net9.0"> |
| 40 | + <dependency id="System.Text.Json" version="9.0.4" /> |
| 41 | + </group> |
| 42 | +</dependencies> |
| 43 | +``` |
| 44 | + |
| 45 | +## New behavior |
| 46 | + |
| 47 | +Starting in .NET 10 Preview 7, directly prunable `PackageReference` items are automatically marked with `PrivateAssets=all` and `IncludeAssets=none`, which excludes them from the generated dependencies for target frameworks where they're provided by the platform. |
| 48 | + |
| 49 | +The same project configuration now generates a *.nuspec* file with the prunable dependency removed from the target framework that provides it (.NET 9): |
| 50 | + |
| 51 | +```xml |
| 52 | +<dependencies> |
| 53 | + <group targetFramework=".NETFramework4.7.2"> |
| 54 | + <dependency id="System.Text.Json" version="9.0.4" /> |
| 55 | + </group> |
| 56 | + <group targetFramework="net9.0"> |
| 57 | + </group> |
| 58 | +</dependencies> |
| 59 | +``` |
| 60 | + |
| 61 | +## Type of breaking change |
| 62 | + |
| 63 | +This is a [behavioral change](../../categories.md#behavioral-change). |
| 64 | + |
| 65 | +## Reason for change |
| 66 | + |
| 67 | +This change ensures that package dependencies accurately reflect the actual requirements for each target framework. It prevents unnecessary package references from appearing in generated packages when those APIs are already provided by the target framework. |
| 68 | + |
| 69 | +## Recommended action |
| 70 | + |
| 71 | +- If you create a package and get a [`NU1510` warning](/nuget/reference/errors-and-warnings/nu1510), follow the instructions there. |
| 72 | +- If you create a package and the generated *.nuspec* dependencies don't contain a referenced package for *any* target framework, remove the reference from the project file as it's not needed. |
| 73 | +- If the referenced package appears in the *.nuspec* file, no action is needed. |
| 74 | + |
| 75 | +## Affected APIs |
| 76 | + |
| 77 | +None. |
| 78 | + |
| 79 | +## See also |
| 80 | + |
| 81 | +- [PrunePackageReference](/nuget/consume-packages/package-references-in-project-files#prunepackagereference) |
| 82 | +- [NU1510 is raised for direct references pruned by NuGet](nu1510-pruned-references.md) |
0 commit comments