Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
JonDouglas opened this issue Dec 2, 2016 · 2 comments
Labels
Area:ErrorHandling warnings and errors/log messages & related error codes. Functionality:Install The install command in VS/nuget.exe
Milestone

Comments

@JonDouglas
Copy link
Contributor

JonDouglas commented Dec 2, 2016

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

  1. Create a File->New Project -> Blank App (Android)

  2. Right Click Project -> Properties

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

  4. Open up NuGet Package Manager (Right Click Project -> Manage NuGet Packages...)

  5. Search for "xamarin android support"

  6. Find the Xamarin.Android.Support.v4 package

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

Attempting to gather dependency information for package 'Xamarin.Android.Support.v4.24.2.1' with respect to project 'App31', targeting 'MonoAndroid,Version=v6.0'
  GET https://api.nuget.org/v3/registration1-gz/xamarin.android.support.v4/index.json
  OK https://api.nuget.org/v3/registration1-gz/xamarin.android.support.v4/index.json 679ms
  GET https://api.nuget.org/v3/registration1-gz/xamarin.android.support.media.compat/index.json
  GET https://api.nuget.org/v3/registration1-gz/xamarin.android.support.core.ui/index.json
  GET https://api.nuget.org/v3/registration1-gz/xamarin.android.support.fragment/index.json
  GET https://api.nuget.org/v3/registration1-gz/xamarin.android.support.core.utils/index.json
  GET https://api.nuget.org/v3/registration1-gz/xamarin.android.support.compat/index.json
  GET https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/FindPackagesById()?id='Xamarin.Android.Support.Compat'
  GET https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/FindPackagesById()?id='Xamarin.Android.Support.Core.Utils'
  GET https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/FindPackagesById()?id='Xamarin.Android.Support.Fragment'
  GET https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/FindPackagesById()?id='Xamarin.Android.Support.Core.UI'
  GET https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/FindPackagesById()?id='Xamarin.Android.Support.Media.Compat'
  OK https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/FindPackagesById()?id='Xamarin.Android.Support.Compat' 617ms
  GET https://api.nuget.org/v3/registration1-gz/xamarin.build.download/index.json
  GET https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/FindPackagesById()?id='Xamarin.Build.Download'
  OK https://api.nuget.org/v3/registration1-gz/xamarin.android.support.core.ui/index.json 705ms
  OK https://api.nuget.org/v3/registration1-gz/xamarin.android.support.fragment/index.json 1486ms
  OK https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/FindPackagesById()?id='Xamarin.Android.Support.Core.UI' 1490ms
  OK https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/FindPackagesById()?id='Xamarin.Build.Download' 1293ms
  OK https://api.nuget.org/v3/registration1-gz/xamarin.build.download/index.json 1530ms
  OK https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/FindPackagesById()?id='Xamarin.Android.Support.Core.Utils' 2300ms
  OK https://api.nuget.org/v3/registration1-gz/xamarin.android.support.media.compat/index.json 2457ms
  OK https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/FindPackagesById()?id='Xamarin.Android.Support.Fragment' 3038ms
  OK https://api.nuget.org/v3/registration1-gz/xamarin.android.support.core.utils/index.json 3378ms
  OK https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/FindPackagesById()?id='Xamarin.Android.Support.Media.Compat' 3457ms
  OK https://api.nuget.org/v3/registration1-gz/xamarin.android.support.compat/index.json 3644ms
Total number of results gathered : 25
Gathering dependency information took 7.42 sec
Summary of time taken to gather dependencies per source :
C:\Users\dougl\Documents\Visual Studio 2015\Projects\App31\packages	-	7.9 ms
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\	-	2.47 ms
https://api.nuget.org/v3/index.json	-	14.63 sec
https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/	-	12.25 sec
Attempting to resolve dependencies for package 'Xamarin.Android.Support.v4.24.2.1' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'Xamarin.Android.Support.v4.24.2.1'
Resolved actions to install package 'Xamarin.Android.Support.v4.24.2.1'
Retrieving package 'Xamarin.Android.Support.Compat 24.2.1' from 'nuget.org'.
Retrieving package 'Xamarin.Android.Support.Core.UI 24.2.1' from 'nuget.org'.
Retrieving package 'Xamarin.Android.Support.Core.Utils 24.2.1' from 'nuget.org'.
Retrieving package 'Xamarin.Android.Support.Media.Compat 24.2.1' from 'nuget.org'.
Retrieving package 'Xamarin.Android.Support.Fragment 24.2.1' from 'nuget.org'.
Retrieving package 'Xamarin.Android.Support.v4 24.2.1' from 'nuget.org'.
For adding package 'Xamarin.Android.Support.Compat.24.2.1' to project 'App31' that targets 'monoandroid60'.
Install failed. Rolling back...
Package 'Xamarin.Android.Support.Compat.24.2.1' does not exist in project 'App31'
Package 'Xamarin.Android.Support.Compat.24.2.1' does not exist in folder 'C:\Users\dougl\Documents\Visual Studio 2015\Projects\App31\packages'
Executing nuget actions took 86.4 ms
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.
========== Finished ==========
Time Elapsed: 00:00:14.9037093

Right off the gate we can tell NuGet that our project target is targeting MonoAndroid,Version=v6.0. Otherwise known as monoandroid60. However inside these logs, there is no mention of what target is trying to be installed. Ideally I should be able to see that monoandroid70 is trying to be installed into a project that is currently targeting monoandroid60. However to find that information out, I would have to:

  1. Go to the NuGet page: https://www.nuget.org/packages/Xamarin.Android.Support.v4/

  2. Download the .nupkg - https://www.nuget.org/api/v2/package/Xamarin.Android.Support.v4/24.2.1

  3. Extract the .nupkg

  4. Go inside the lib folder and see this library only supports MonoAndroid70.

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:

  1. What the project target is currently (In this case monoandroid60)

  2. What the potential "to-be-installed" package target(s) were found (In this case monoandroid70)

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

  4. 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.0 for 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 the package 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 the package framework that uses the lib/ structure.

@rrelyea rrelyea added the Functionality:Install The install command in VS/nuget.exe label Dec 5, 2016
@rrelyea rrelyea added this to the Future-1 milestone Dec 5, 2016
@rrelyea rrelyea added the Area:ErrorHandling warnings and errors/log messages & related error codes. label Dec 5, 2016
@nkolev92
Copy link
Member

nkolev92 commented Sep 25, 2017

I think the logging concern has been addressed by the error and warnings work by @emgarten.

This is available in 4.3 nuget / 15.3 VS and later versions.

In your scenario you'd have an error code like the following: https://docs.microsoft.com/en-us/nuget/reference/errors-and-warnings#nu1201

Package System.ComponentModel.EventBasedAsync 4.0.11 is not compatible with netstandard1.3 (.NETStandard,Version=v1.3). Package System.ComponentModel.EventBasedAsync 4.0.11 supports:
- monoandroid10 (MonoAndroid,Version=v1.0)
- monotouch10 (MonoTouch,Version=v1.0)
- net45 (.NETFramework,Version=v4.5)
- netcore50 (.NETCore,Version=v5.0)
- netstandard1.0 (.NETStandard,Version=v1.0)
- portable-net45+win8+wp8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile259)
- win8 (Windows,Version=v8.0)
- wp8 (WindowsPhone,Version=v8.0)
- wpa81 (WindowsPhoneApp,Version=v8.1)
- xamarinios10 (Xamarin.iOS,Version=v1.0)
- xamarinmac20 (Xamarin.Mac,Version=v2.0)
- xamarintvos10 (Xamarin.TVOS,Version=v1.0)
- xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0)

There's also this related story that would eventually lead to users seeing only applicable packages in the Package Manager UI.
#5725

@JonDouglas
Copy link
Contributor Author

Perfect, thanks for following up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area:ErrorHandling warnings and errors/log messages & related error codes. Functionality:Install The install command in VS/nuget.exe
Projects
None yet
Development

No branches or pull requests

3 participants