简体   繁体   中英

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?

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

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.

Alright, so after three weeks of banging my head on this, I have finally ( FINALLY ) solved the problem. Here is my new, working project.json :

{
    ...

    "frameworks": {
        "dotnet": {
            "dependencies": {
                "System.Runtime": "4.0.20"
            }
        },
        ".NETPortable,Version=v4.5,Profile=Profile111": {
            "frameworkAssemblies": {
                "System.Runtime": ""
            }
        }
    }
}

Thanks to Mark for giving me the idea and whoever these guys are.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM