NuGet / Home

Repo for NuGet Client issues
Other
1.49k stars 250 forks source link

[Bug]: NU1701 - Package restore errors should mention which dependant package it came from #11758

Open xPaw opened 2 years ago

xPaw commented 2 years ago

NuGet Product Used

dotnet.exe

Product Version

6.1.0.103

Worked before?

No response

Impact

It bothers me. A fix would be nice

Repro Steps & Context

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0-windows</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="SkiaSharp.Views.WindowsForms" Version="2.88.0-preview.179" />
  </ItemGroup>
</Project>

dotnet restore and nuget in Visual Studio 2022.

In my project I have SkiaSharp.Views.WindowsForms package, which depends on OpenTK (>= 3.1.0), OpenTK.GLControl (>= 3.1.0).

My project itself also depended on OpenTK.GLControl, while attempting an upgrade I briefly uninstalled this package, but nuget keeps saying that it fails to restore it.

It's not obvious that it's still trying to restore it because another package depends on it. This error message should print the dependency path.

Verbose Logs

Determining projects to restore... GUI.csproj : error NU1701: Package 'OpenTK.GLControl 3.1.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net6.0-windows7.0'. This package may not be fully compatible with your project. [ValveResourceFormat.sln]

GUI.csproj does not have a reference to this package directly.

kartheekp-ms commented 2 years ago

I agree that error message could be improved by adding package dependency path. One option that I can think of right now is, look at the package dependencies in either project.assets.json file or depedencies node in VS solution explorer.

image

kenans commented 2 years ago

NU1701 used to be a warning and is still documented so. I wonder if there's any update that's elevated it to an error recently?

Another related issue on dotnet SDK https://github.com/dotnet/sdk/issues/25338, which upgraded Nuget dependency from 6.1.x to 6.2.x. The issue also surfaced as error NU1701

-- Correction -- NU1701 are still warnings. We have <TreatWarningsAsErrors>true</TreatWarningsAsErrors> set on our project, and that's why it was surfaced as errors

xPaw commented 2 years ago

I wonder if there's any update that's elevated it to an error recently?

I had warnings as errors in my csproj.

kenans commented 2 years ago

UPDATE: we resolved the issue by removing all the incompatible transitive dependencies. After that, we no longer have NU1701 warnings. This sample project explains why NU1701 wasn't reported before, and why it got surfaced out since Nuget 6.2

xPaw commented 2 years ago

This issue is about making the warning more informative, not resolving it.