尝试使用面向 .Net 4.6.1 的便携式类库安装 EF Core [英] Trying to install EF Core with Portable Class Library targeting .Net 4.6.1

查看:30
本文介绍了尝试使用面向 .Net 4.6.1 的便携式类库安装 EF Core的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次使用 VS2015 试验 EF Core、ASP Net Core 和可移植类库.可以说我很沮丧.

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.

我想创建一个可以安装 EntityFramework.Core 的库.这个库需要在 WPF 应用程序和 ASP NET Core Web 应用程序中使用 - 现在忽略任何好的分层应用程序概念.我的想法是创建一个可移植的类库.

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.

使用我针对 .NET 4.6 和 ASP Net Core 的项目模板...

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

我得到一个带有类和 project.json 文件的项目,如下所示:

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"
        }
    }
}

现在,当我从 nuget 安装 EntityFramework.Core 包时...

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

...我得到以下输出:

...I get the following output:

Restoring packages for 'Acme.PCLEFClassLib'.
Restoring packages for K:TFSTestAppsProjectsDotNetCoreAcme.PCL1Acme.PCL1project.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 ==========

是否真的可以在便携式类库中安装 EF Core?如果是这样 - 我需要对项目做什么?

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.

更新 1

尝试在我的 PCL 中安装 EntityFramework.MicrosoftSqlServer.

Tried installing EntityFramework.MicrosoftSqlServer in my PCL.

鉴于在创建使用 dnxcore50 框架的标准 ASP Net Core 项目时安装了 EntityFramework.MicrosoftSqlServer.如果我在 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.

如果是这样,那么它如何安装到 ASP NET Core 项目中.

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

更新 2

我创建了一个针对 .NET 4.5.1 的新 PCL.然后我通过 Nuget 将 EntityFramework.MicrosoftSqlServer 7.0.0-rc1-final 安装到其中,并且安装没有问题.虽然我现在不能重复这一点.我刚刚创建了一个单独的解决方案,其中包含一个针对 ASP NET Core 和 .NET 4.5.1 的 PCL 库项目.现在输出以下内容:

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:TFSTestAppsProjectsDotNetCoreAnotherPCLEFFUPpackages'
Invalid portable frameworks.

安装 EntityFramework.Core.7.0.0-rc1-final 也会发生同样的情况.

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.

推荐答案

我不知道这将如何满足您的便携式类需求,但对于常规 .NET(4.6 或其他),我发现了以下内容.(见下面的咆哮)

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:

添加nuget包源(选项-包源-添加(加)

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

如果您是为 SqlServer 安装,只需安装:

If you are installing for SqlServer, just install this:

Microsoft.EntityFrameworkCore.SqlServer

Microsoft.EntityFrameworkCore.SqlServer

或者选择另一个顶级依赖项,它将获取所有其他需要的依赖项.

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

*[开始咆哮]那只是通过在 EF github 讨论中四处寻找.他们没有实际的描述来解释现在要做什么,这是完全不可原谅的.他们应该删除RC"1 版本,其中包含所有错误,并且其设计与他们现在的工作完全不同,并且已经超过 5 个月没有更新(!这是与预-release' 标记已检查!),完全来自 nuget.

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

让我补充一点:我喜欢这些人所做的一切,我喜欢新的东西,很多非常好的东西.但是我们不应该因为一个所谓的并且仍然被标记为RC"版本而被搁置半年,因为它充满了已经在彻底重新设计的 rc2 版本中修复的错误,他们没有公开.[/end-rant]*

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]*

这篇关于尝试使用面向 .Net 4.6.1 的便携式类库安装 EF Core的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆