fsprojects / Paket

A dependency manager for .NET with support for NuGet packages and Git repositories.
https://fsprojects.github.io/Paket/
MIT License
2.02k stars 524 forks source link

Creating a .Net standard2.0 project that also has Android references seems to create unnecessary transient dependencies #2802

Open 7sharp9 opened 7 years ago

7sharp9 commented 7 years ago

Description

Creating a .Net standard2.0 project that also has Android references to Xamarin.Android.Support.v7.AppCompatseems to create an unnecessary transient dependency toXamarin.Android.Support.v7.AppCompat`.

The .Net standard project references Microsoft.Identity.Client which only has a reference to Xamarin.Android.Support.v7.AppCompat in the MonoAndroid version of the assembly yet dotnet restore seems to try and restore that package.

Repro steps

I created a repo here: https://github.com/7sharp9/paket-mobile-test

clone https://github.com/7sharp9/paket-mobile-test
cd paket-mobile-test
dotnet restore Core

Expected behavior

dotnet restore Core works successfully

Actual behavior

dotnet restore Core fails with

dotnet restore Core                                                                                                                                                
  Restoring packages for /Users/dave.thomas/Documents/paket-mobile-test/Core/Core.fsproj...
/Users/dave.thomas/Documents/paket-mobile-test/Core/Core.fsproj : error NU1202: Package Xamarin.Android.Support.v7.AppCompat 25.4.0.2 is not compatible with netstandard2.0 (.NETStandard,Version=v2.0). Package Xamarin.Android.Support.v7.AppCompat 25.4.0.2 supports: monoandroid70 (MonoAndroid,Version=v7.0)

Known workarounds

?

7sharp9 commented 7 years ago

I have omitted an Android project but it would have paket references to almost all the nugets in the default group.

forki commented 7 years ago

@matthid and myself are not 100% sure what happens. But if you restrict it to netstandard2 then it restores and builds fine. see https://github.com/7sharp9/paket-mobile-test/pull/1

forki commented 7 years ago

I think it is an issue with netstandard 1.6 vs. 2 - apparently android 7 is compatible to netstandard1.6 but for some reason not to 2.0

7sharp9 commented 7 years ago

So ... If I add an android project then I would have to add a separate group for it without the net standard restriction?

forki commented 7 years ago

that might work. we don't really understand yet why the monoandroid is incompatible to netstandard2. maybe nuget bug!?

forki commented 7 years ago

ok I think it's a paket bug. The following happens: in every situation where Xamarin.Android.Support.v7.AppCompat is used we see >= monoandroid7.0 as restriciton. that's good.

but when we lock the package down we lose that information for some reason.

forki commented 7 years ago

no idea where it get's lost

forki commented 7 years ago

ok now I know: it's because it's directly in deps file.

merge this one: https://github.com/7sharp9/paket-mobile-test/pull/2/files#diff-b27553841b4413a24ed1b9aff865105bL13

7sharp9 commented 7 years ago
nuget Xamarin.Android.Support.v4
nuget Xamarin.Android.Support.v7.AppCompat

Both of those are android requirements but not for the core projects.

matthid commented 7 years ago

I agree that this is a problem or at least quite unexpected. The problem is that we don't properly calculate restrictions in that case:

Somehow this at least feels somehow wrong:

references file take a subtree, but in the above situation the subtree needs/can to be trimmed further (by evaluating restrictions again?)