Skip to content

NoWarn=NU1511 doesn't work on a ProjectReference - ProjectReference item does not support NoWarn for NuGet warnings #14121

@ViktorHofer

Description

@ViktorHofer

There are cases where we want to reference a project that is inbox in a given framework which will emit a NU1511 warning as the direct P2P can't be pruned from the restore graph. This is fine as in such a case, it shouldn't be pruned. It would be great if we could NoWarn this warning just for that single P2P so that we still get others flagged.

Example

a.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\b\b.csproj" NoWarn="NU1511" />
  </ItemGroup>

</Project>

b.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <PackageId>System.Collections.Immutable</PackageId>
  </PropertyGroup>

</Project>
C:\temp\prunep2p> C:\git\dotnet-sdk-10.0.100-preview.2.25111.9-win-x64\dotnet.exe restore .\a\a.csproj
Restore succeeded with 1 warning(s) in 0.5s
    C:\temp\prunep2p\a\a.csproj : warning NU1511: A ProjectReference cannot be pruned, System.Collections.Immutable.                                                                                                                                          
Build succeeded with 1 warning(s) in 1.0s

@nkolev92 maybe NoWarn on an item is only supported for PackageReference and not ProjectReference?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions