C# 如何从 NuGet 安装 EntityFramework 5.0(和其他旧版本)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19956925/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 16:13:16  来源:igfitidea点击:

How to install EntityFramework 5.0 (and other older versions) from NuGet?

c#asp.netentity-framework-5entity-framework-6

提问by thenewseattle

I installed EF 5.0 into the .DAL, now I want to install EF 5.0 into .BLL from Nuget

我将 EF 5.0 安装到 .DAL,现在我想从 Nuget 将 EF 5.0 安装到 .BLL

But the default online Nuget package always comes up with 6.0, which gives error when used together with the 5.0 EF I use in DAL.

但是默认的在线 Nuget 包总是带有 6.0,当与我在 DAL 中使用的 5.0 EF 一起使用时会出错。

Where can I install the 5.0 version of EntityFramework into my Nuget packages??

在哪里可以将 EntityFramework 的 5.0 版本安装到我的 Nuget 包中?

采纳答案by devnull

View -> Other windows -> Package Manager Console then run install-package entityframework -version 5.0.0.0.

查看 -> 其他窗口 -> 包管理器控制台然后运行 install-package entityframework -version 5.0.0.0

Add -project <project.name>if you want to install it in a specific project.

-project <project.name>如果要将其安装在特定项目中,请添加。

回答by Dan B

here is what I experienced: (before I begin... kudos to devnull for the answer).

这是我的经历:(在我开始之前......感谢 devnull 的答案)。

I clicked on:

我点击了:

1) View -> Other windows -> Package Manager Consolethen ran

1)查看->其他窗口->包管理器控制台然后运行

2) install-package entityframework -version 5.0.0.0.

2) install-package entityframework -version 5.0.0.0

The uninstall started, but then rolled back, as it detected I already had installed Entity Framework (EF) 6.0.2 ...

卸载开始,但随后回滚,因为它检测到我已经安装了实体框架 (EF) 6.0.2 ...

>PM> install-package entityframework -version 5.0.0.0

>PM> 安装包 entityframework -version 5.0.0.0

Installing 'EntityFramework 5.0.0'. You are downloading EntityFramework from Microsoft, the license agreement to which is available at http://go.microsoft.com/fwlink/?LinkId=253898&clcid=0x409. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device. Successfully installed 'EntityFramework 5.0.0'. *****Install failed. Rolling back...***** install-package : Already referencing a newer version of 'EntityFramework'. At line:1 char:1 + install-package entityframework -version 5.0.0.0 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

安装“EntityFramework 5.0.0”。您正在从 Microsoft 下载 EntityFramework,其许可协议可从http://go.microsoft.com/fwlink/?LinkId=253898&clcid=0x409 获得。检查包中是否有其他依赖项,这些依赖项可能带有自己的许可协议。您对包和依赖项的使用构成您接受他们的许可协议。如果您不接受许可协议,请从您的设备中删除相关组件。已成功安装“EntityFramework 5.0.0”。*****安装失败。正在回滚...***** install-package :已经引用了较新版本的“EntityFramework”. 在 line:1 char:1 + install-package entityframework -version 5.0.0.0 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException +fullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

So then I uninstalled the Entity Framework 6.0.2 and found it had a dependency that also needed to be removed... then I was finally able to uninstall the Entity Framework 6.0.2 and then add the Entity Framework 5.0.0.0

所以后来我卸载了Entity Framework 6.0.2,发现它有一个依赖也需要删除......然后我终于能够卸载Entity Framework 6.0.2,然后添加Entity Framework 5.0.0.0

PM> uninstall-package entityframework -version 6.0.2uninstall-package : Unable to uninstall 'EntityFramework 6.0.2' because 'AnotherFakeDbSet 3.0.0.0' depends on it.

PM> uninstall-package entityframework -version 6.0.2uninstall-package :无法卸载“EntityFramework 6.0.2”,因为“AnotherFakeDbSet 3.0.0.0”依赖于它。

So then I uninstalled these two and installed Entity Framework 5.0.0.0

然后我卸载了这两个并安装了 Entity Framework 5.0.0.0

PM> uninstall-package AnotherFakeDbSet -version 3.0.0.0

PM> uninstall-package entityframework -version 6.0.2

PM> install-package entityframework -version 5.0.0.0

PM> 卸载包 AnotherFakeDbSet -version 3.0.0.0

PM> 卸载包 entityframework -version 6.0.2

PM> 安装包 entityframework -version 5.0.0.0

I like the console... quicker than searching for the packages if you know the version #. And if you haven't checked out "Powershell" (the basis for the console -- I find it's time well spent - it allows for virtually unlimited automation)

我喜欢控制台......如果你知道版本#,那么比搜索包要快。如果你还没有检查过“Powershell”(控制台的基础——我觉得时间很值得——它允许几乎无限的自动化)

回答by vibs2006

Older versions of Entity Framework or other similar packages can be installed using Package Manager Console onlyin earlier versions of Visual Studio (prior to 2015). In Visual Studio 2015 there is an option of manually selecting version before install but in Visual Studio 2010,2012 you need to use package manager console only.

旧版本的实体框架或其他类似的包只能使用包管理器控制台安装在早期版本的 Visual Studio(2015 年之前)中。在 Visual Studio 2015 中,有一个在安装前手动选择版本的选项,但在 Visual Studio 2010、2012 中,您只需要使用包管理器控制台。

Simple browse to the link Nuget Explorerand click on the specific entity versionthat you have to install.

简单浏览到链接Nuget Explorer单击您必须安装的特定实体版本

You'll see that Studio automatically shows the Package Manager console code.

您将看到 Studio 自动显示包管理器控制台代码。

For example I was working on a project that required Entity Framework 4.1 So here was my code. Entity Framework Package Manager Console Command Snapshot

例如,我正在开发一个需要 Entity Framework 4.1 的项目,这是我的代码。实体框架包管理器控制台命令快照