Edit

NuGet Warning NU1510

Scenario 1

PackageReference System.Text.Json will not be pruned. This package is automatically available and does not need to be referenced explicitly. Remove the PackageReference item

Issue

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. 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.

This warning only affects packages registered for pruning through the PrunePackageReference feature. It is only raised when the PackageReference in question can be completely removed from the project.

Example 1

When the targeted .NET SDK includes an equivalent version, dependency conflict resolution selects the SDK-bundled assembly:

  <PropertyGroup>
    <!-- 'System.Text.Json' is SDK-bundled in 'net10.0' -->
    <TargetFramework>net10.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <!-- The assembly provided by this reference will not be used -->
    <PackageReference Include="System.Text.Json" Version="10.0.0" />
  </ItemGroup>

Example 2

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:

  <PropertyGroup>
    <!-- 'System.Text.Json' is SDK-bundled in both TFMs -->
    <TargetFrameworks>net9.0;net10.0</TargetFrameworks>
  </PropertyGroup>

  <ItemGroup>
    <!-- Neither of the assemblies provided by these references will be used -->
    <PackageReference Include="System.Text.Json" Version="10.0.0" Condition="'$(TargetFramework)' == 'net10.0'"/>
    <PackageReference Include="System.Text.Json" Version="9.0.4" Condition="'$(TargetFramework)' == 'net9.0'"/>
  </ItemGroup>

Solution

Remove the unnecessary PackageReference.

Scenario 2

PackageReference Microsoft.Extensions.Caching.Memory will not be pruned. This package is automatically available and does not need to be referenced explicitly. Remove the PackageReference item

Issue

The list of packages used for pruning is determined by the direct FrameworkReference items of the current project. FrameworkReference items are transitive. However, when the current project inherits a framework reference through a ProjectReference, pruning doesn't use that transitive framework reference to remove packages. Note that this package will be removed by build-time conflict resolution.

Example

In this example, Library.csproj references Microsoft.AspNetCore.App, and Consumer.csproj references Library.csproj. Without a direct FrameworkReference in Consumer.csproj, NuGet can't determine that the package is prunable. As a result, Microsoft.Extensions.Caching.Memory isn't considered prunable in the consumer project.

  <!-- Library.csproj -->
  <Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
      <TargetFramework>net10.0</TargetFramework>
    </PropertyGroup>

    <ItemGroup>
      <FrameworkReference Include="Microsoft.AspNetCore.App" />
    </ItemGroup>
  </Project>
  <!-- Consumer.csproj -->
  <Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
      <TargetFramework>net10.0</TargetFramework>
    </PropertyGroup>

    <ItemGroup>
      <ProjectReference Include="..\Library\Library.csproj" />
      <PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
    </ItemGroup>
  </Project>

Add the FrameworkReference directly to Consumer.csproj. NuGet can then determine that Microsoft.Extensions.Caching.Memory is provided by the shared framework. It raises NU1510 for the unnecessary direct package reference.

  <ItemGroup>
    <ProjectReference Include="..\Library\Library.csproj" />
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
  </ItemGroup>

Solution

Add the matching FrameworkReference directly to the current project. Then remove the unnecessary PackageReference.

Note

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:

  <PropertyGroup>
    <!-- 'System.Text.Json' is not SDK-bundled in 'net48' -->
    <TargetFrameworks>net10.0;net48</TargetFrameworks>
  </PropertyGroup>

  <ItemGroup>
    <!-- This reference is needed in 'net48' - NU1510 is not raised -->
    <PackageReference Include="System.Text.Json" Version="9.0.7" />
  </ItemGroup>