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

查看:95
本文介绍了尝试使用面向.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:\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 ==========

实际上可以在便携式类库中安装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.

鉴于创建标准ASP Net Core项目(使用dnxcore50框架)时已安装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:\TFS\TestApps\Projects\DotNetCore\AnotherPCLEFFUP\packages'
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或更高版本),我发现了以下内容. (请参阅下面的rant)

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)

  • Name: 'aspnetrelease' (or whatever you want)
  • Source: 'https://www.myget.org/F/aspnetrelease/api/v3/index.json'

如果要为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.

让我补充:我爱这些家伙正在做的一切,我喜欢新的东西,很多真正的好东西.但是,当我们已经充满了彻底重新设计的rc2版本中已修正的错误时,我们不应该被搁置半年,而应该将 still 标记为"RC"版本尚未公开. [/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天全站免登陆