Trying to install EF Core with Portable Class Library targeting .Net 4.6.1

entity-framework entity-framework-core portable-class-library

Question

This is my first time experimenting with EF Core, ASP Net Core and Portable Class Libraries with VS2015. Fair to say I am getting frustrated.

I want to create a library where I can install EntityFramework.Core. This library needs to be used in a WPF Application and an ASP NET Core Web Application - ignoring any good layered application concepts for now. My thought was to create a Portable Class Library.

Using the project template where I target .NET 4.6 and ASP Net Core...

Targets

I get a project with a class and a project.json file as follows:

{
    "supports": {
        "net46.app": {},
        "dnxcore50.app": {}
    },
    "dependencies": {
        "Microsoft.NETCore": "5.0.0",
        "Microsoft.NETCore.Portable.Compatibility": "1.0.0"
    },
    "frameworks": {
        "dotnet": {
            "imports": "portable-net452"
        }
    }
}

Now when I install EntityFramework.Core package from nuget...

Install EF Core Nuget

...I get the following output:

Restoring packages for 'Acme.PCLEFClassLib'.
Restoring packages for K:\TFS\TestApps\Projects\DotNetCore\Acme.PCL1\Acme.PCL1\project.json...
Detected package downgrade: System.Reflection from 4.1.0-beta-23225 to 4.0.10 
 Acme.PCLEFClassLib (>= 1.0.0) -> EntityFramework.Core (>= 7.0.0-rc1-final) -> Microsoft.Extensions.DependencyInjection.Abstractions (>= 1.0.0-rc1-final) -> System.Reflection (>= 4.1.0-beta-23225) 
 Acme.PCLEFClassLib (>= 1.0.0) -> EntityFramework.Core (>= 7.0.0-rc1-final) -> System.Reflection (>= 4.0.10)
Detected package downgrade: System.Reflection from 4.1.0-beta-23225 to 4.0.10 
 Acme.PCLEFClassLib (>= 1.0.0) -> EntityFramework.Core (>= 7.0.0-rc1-final) -> Microsoft.Extensions.Logging.Abstractions (>= 1.0.0-rc1-final) -> System.Reflection (>= 4.1.0-beta-23225) 
 Acme.PCLEFClassLib (>= 1.0.0) -> EntityFramework.Core (>= 7.0.0-rc1-final) -> System.Reflection (>= 4.0.10)
Version conflict detected for System.Collections. 
 Acme.PCLEFClassLib (>= 1.0.0) -> EntityFramework.Core (>= 7.0.0-rc1-final) -> System.Collections (>= 4.0.11-beta-23516) 
 Acme.PCLEFClassLib (>= 1.0.0) -> Microsoft.NETCore.Portable.Compatibility (>= 1.0.0) -> Microsoft.NETCore.Runtime (>= 1.0.0) -> Microsoft.NETCore.Runtime.CoreCLR-x86 (>= 1.0.0) -> System.Collections (= 4.0.10).
EntityFramework.Core 7.0.0-rc1-final is not compatible with .NETPlatform,Version=v5.0.
Some packages are not compatible with .NETPlatform,Version=v5.0.
Ix-Async 1.2.5 is not compatible with DNXCore,Version=v5.0.
Remotion.Linq 2.0.1 is not compatible with DNXCore,Version=v5.0.
Some packages are not compatible with DNXCore,Version=v5.0.
Ix-Async 1.2.5 is not compatible with DNXCore,Version=v5.0 (win7-x86).
Remotion.Linq 2.0.1 is not compatible with DNXCore,Version=v5.0 (win7-x86).
Some packages are not compatible with DNXCore,Version=v5.0 (win7-x86).
Ix-Async 1.2.5 is not compatible with DNXCore,Version=v5.0 (win7-x64).
Remotion.Linq 2.0.1 is not compatible with DNXCore,Version=v5.0 (win7-x64).
Some packages are not compatible with DNXCore,Version=v5.0 (win7-x64).
Package restore failed for 'Acme.PCLEFClassLib'.
Package restore failed. Rolling back package changes for 'Acme.PCLEFClassLib'.
========== Finished ==========

Is it actually possible to install EF Core in a Portable Class Library? If so how - what do I need to do with the project?

I just feel I am going round in circles looking for solutions on line.

UPDATE 1

Tried installing EntityFramework.MicrosoftSqlServer in my PCL.

Given that EntityFramework.MicrosoftSqlServer is installed when creating a standard ASP Net Core project - which uses the dnxcore50 framework. How come if I do similar in the PCL, is complains that:

EntityFramework.MicrosoftSqlServer 7.0.0-rc1-final is not compatible with .NETPlatform,Version=v5.0.

If that is the case then how come it installs into a ASP NET Core project.

UPDATE 2

I created a new PCL targeting .NET 4.5.1. I then installed EntityFramework.MicrosoftSqlServer 7.0.0-rc1-final into that via Nuget, and it installs no problem. Although I cannot repeat this now. I've just created a separate solution with a PCL Library project targeting ASP NET Core and .NET 4.5.1. This outputs the following now:

Attempting to gather dependency information for package 'EntityFramework.MicrosoftSqlServer.7.0.0-rc1-final' with respect to project 'AnotherPCLEFFUP', targeting '.NETPortable,Version=v4.5,Profile=Profile75'
Attempting to resolve dependencies for package 'EntityFramework.MicrosoftSqlServer.7.0.0-rc1-final' with DependencyBehavior 'Lowest'
Resolving actions to install package 'EntityFramework.MicrosoftSqlServer.7.0.0-rc1-final'
Resolved actions to install package 'EntityFramework.MicrosoftSqlServer.7.0.0-rc1-final'
Install failed. Rolling back...
Package 'EntityFramework.MicrosoftSqlServer.7.0.0-rc1-final' does not exist in project 'AnotherPCLEFFUP'
Package 'EntityFramework.MicrosoftSqlServer.7.0.0-rc1-final' does not exist in folder 'K:\TFS\TestApps\Projects\DotNetCore\AnotherPCLEFFUP\packages'
Invalid portable frameworks.

Same happens installing EntityFramework.Core.7.0.0-rc1-final.

Fair to say, this is utterly frustrating. Maybe I am barking up the wrong tree or just barking mad today.

Popular Answer

I don't know how this will work for your Portable Class needs, but for regular .NET (4.6 or etc), I discovered the following. (see rant below)

So I don't know if this is 'kosher' or not, but this source works right now:

Add nuget package source (Options - Package Sources - Add (plus)

If you are installing for SqlServer, just install this:

Microsoft.EntityFrameworkCore.SqlServer

Or choose another top-level dependency which will pick up all the others needed.

*[begin-rant] That was only by scrounging around on the EF github discussions. It is totally inexcusable that they do not have a practical description explaining what to do right now. They should pull the "RC"1 version, with all of its bugs, and with its radical different design from what they are working on now, and which hasn't been updated for over 5 months (! and this is with the 'pre-release' mark checked!), entirely from nuget.

Let me add: I love everything these guys are doing, I love the new bits, lots of really good stuff. But we shouldn't be left hanging for half a year with a supposedly and still marked as "RC" release when it is full of bugs that have already been fixed in the radically redesigned rc2 version, which they haven't publicized. [/end-rant]*



Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow