Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't this .NET Core package compatible with my PCL?

I have a PCL that targets the following platforms:

  • .NET Framework 4.5
  • Windows 8
  • Windows Phone 8.1

I also have another package (called Enu), based off .NET Core and project.json, that I would like to use in this PCL. My problem is, when I try to install the .NET Core package into my PCL, I receive an error message saying that the PCL isn't compatible with the package.

PM> Install-Package Enu
# lots of output...
Install failed. Rolling back...
Package 'Enu 4.4.0' does not exist in project 'PclDummy'
Package 'Enu 4.4.0' does not exist in folder 'C:\Users\James\Documents\Visual Studio 2015\Projects\PclDummy\packages'
Install-Package : Could not install package 'Enu 4.4.0'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile111', 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.

After digging into the issue for a bit, I found out that a package Enu depends on, specifically System.Runtime (v4.0.0), appeared to be having issues as well (related post) installing on my PCL. The strange thing is, while it claims to be incompatible with my library, it supports all of the target platforms I do, so I don't see why this is the case.


TL;DR: NuGet won't allow a .NET Core package to be installed on PCL because it thinks they're incompatible. After investigating, I found out the root of the problem was a dependency of the package was incompatible with the PCL, even though it supports all of the platforms my PCL does. Why is this happening?

Here's the project.json file for the .NET Core package, am I doing anything wrong?

like image 343
James Ko Avatar asked Jan 07 '23 11:01

James Ko


2 Answers

What you're trying is not supported, because you're creating a PCL which allows only the common subset of .NET 4.5, Windows 8 and Windows Phone 8.1 and you're trying to add a reference to this PCL which is a superset of the API you're allowing. This would create a conflict, because the Enu package might use APIs that are not available on .NET 4.5, Windows 8 and/or Windows Phone 8.1.

To use a .NET Core library, you must create a .NET 4.5 library or use a replacement of the Enu library which is itself a PCL which uses the same (.NET 4.5, Windows 8, Windows Phone 8.1)or a smaller subset of the .NET API (.NET 4.5, Windows 8, Windows Phone 8.1 and e.g. Windows Phone 8 Silverlight).

EDIT: A look at your NuGet package reveals, that you have a library which targets .NET 4.5, Windows 8, and Windows Phone 8.1, but you have different assemblies for all platforms, but what you'd need to use it in a PCL is a single assembly which can be used across all platforms. The NuGet platform identifier would be "portable-net45+win+wpa81".

like image 192
Mark Avatar answered Jan 14 '23 03:01

Mark


Targeting dotnet in your project.json will not include Windows 8 and Windows Phone 8.1. Try adding netcore45 and wpa81 in your target frameworks.

like image 40
Dealdiane Avatar answered Jan 14 '23 02:01

Dealdiane