Provide an empowering error message for incompatible packages. Also include a warning to the user that the package will not install if frameworks mismatch. #4051
Labels
Area:ErrorHandling
warnings and errors/log messages & related error codes.
Functionality:Install
The install command in VS/nuget.exe
Milestone
Details about Problem
There is an inconsistency I've noticed when helping mostly Xamarin customers with NuGet. The problem is pretty much the following:
Users who do not understand how NuGet targets work are prevented by the NuGet Package Manager to a decent resolution.
Because of this, users have to go out and find a resolution instead of having the NuGet Package Manager give a more empowering error message / prevent the user from doing the action in the first place.
Version Details
NuGet product used (NuGet.exe | VS UI | Package Manager Console | dotnet.exe):
VS UI
NuGet version (x.x.x.xxx):
NuGet Package Manager 3.5.0
dotnet.exe --version (if appropirate):
N/A (appropriate is spelled incorrectly in the template above though)
VS version (if appropriate):
VS 2015 14.0.25431.01 Update 3
OS version (i.e. win10 v1607 (14393.321)):
win10
Detailed repro steps so we can see the same problem
(Ensure Xamarin.Android is installed before continuing) - https://www.xamarin.com/download-it
Create a
File
->New Project
->Blank App (Android)
Right Click Project
->Properties
Change
Compile using Android version:
to Android 6.0 or lower (Install API 23 in the SDK manager if you haven't installed any previous)Open up NuGet Package Manager (
Right Click Project
->Manage NuGet Packages...
)Search for "xamarin android support"
Find the Xamarin.Android.Support.v4 package
Try to install the package (tested with 24.2.1 latest stable)
Now on this page we see no notice of what Android API version this library requires(AKA
MonoAndroidXX
version). This already can make users fail right from the gate. Let's look at the output we get for this.Right off the gate we can tell NuGet that our
project target
is targetingMonoAndroid,Version=v6.0
. Otherwise known asmonoandroid60
. However inside these logs, there is no mention of whattarget
is trying to be installed. Ideally I should be able to see thatmonoandroid70
is trying to be installed into a project that is currently targetingmonoandroid60
. However to find that information out, I would have to:Go to the NuGet page: https://www.nuget.org/packages/Xamarin.Android.Support.v4/
Download the
.nupkg
- https://www.nuget.org/api/v2/package/Xamarin.Android.Support.v4/24.2.1Extract the
.nupkg
Go inside the
lib
folder and see this library only supportsMonoAndroid70
.Now let's look at the error we get:
Could not install package 'Xamarin.Android.Support.Compat 24.2.1'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v6.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
This doesn't really help me at all other than tell me that
MonoAndroid60
is an incorrect target. It also tells me to contact the package author which I think most package authors wouldn't really appreciate over simple installation issues.Proposal:
I believe these types of error messages need to be empowered. They need to tell the user a couple of things:
What the project
target
is currently (In this casemonoandroid60
)What the potential "to-be-installed" package
target
(s) were found (In this casemonoandroid70
)If there is a mismatch of
target
(s), the user should be warned that it will not install in their project as it is not a supported framework.If the user is warned and proceeds, the error message should be more friendly such as:
Could not install package 'Xamarin.Android.Support.Compat 24.2.1' with targets 'MonoAndroid,Version=v7.0'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v6.0', but the package does not contain any assembly references or content files that are compatible with that framework. You may need to change your project that targets 'MonoAndroid,Version=v6.0' to
MonoAndroid,Version=v7.0for this package to install correctly. For more information, contact the package author.
This is also a problem in other frameworks, but since I mainly work in Xamarin, I figured the use case would be more appropriate.
EDIT 1
I did come across a tool that would be somewhat ideal for this situation and explain it better:
http://nugettoolsdev.azurewebsites.net/3.5.0-beta2-1484/framework-compatibility?project=monoandroid60&package=monoandroid70
For example in this case, because the project framework is lower than the package framework it is
unsupported
. It would be nice if there's a way to get thepackage framework
from metadata so that it's easier to validate these scenarios. I looked through the source code and API docs, but I couldn't figure out a sane way to get thepackage framework
that uses thelib/
structure.The text was updated successfully, but these errors were encountered: