asp.net-mvc EntityFramework 包未安装在项目上

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11923077/
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-09-08 02:09:51  来源:igfitidea点击:

The EntityFramework package is not installed on project

asp.net-mvcentity-frameworkvisual-studionuget-package

提问by user1016313

I am having trouble getting the EF to install on my very simple project called 'Match' (just now learning MVC, better late than never). The general context here is that I created the Model class with only 2 fields and now I want to change the Model class to have a few more fields/properties. I have made the change in the Model class and am now trying to update the DB to match. I am trying to use Update-Database from EF to do that.

我在让 EF 安装在我名为“Match”的非常简单的项目上时遇到了麻烦(刚刚学习 MVC,迟到总比没有好)。这里的一般上下文是我创建了只有 2 个字段的 Model 类,现在我想将 Model 类更改为有更多的字段/属性。我已经在 Model 类中进行了更改,现在正在尝试更新数据库以匹配。我正在尝试使用 EF 的 Update-Database 来做到这一点。

PM> install-package EntityFramework 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'. Successfully added 'EntityFramework 5.0.0' to Match.

Type 'get-help EntityFramework' to see all available Entity Framework commands.

PM> Enable-Migrations Get-Package : A parameter cannot be found that matches parameter name 'ProjectName'. At C:\Users\Dave\Documents\Visual Studio 2010\Projects\Match\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:611 char:40 + $package = Get-Package -ProjectName <<<< $project.FullName | ?{ $_.Id -eq 'EntityFramework' } + CategoryInfo : InvalidArgument: (:) [Get-Package], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,NuGet.PowerShell.Commands.GetPackageCommand

The EntityFramework package is not installed on project 'Match'.

PM> install-package EntityFramework 您正在从 Microsoft 下载 EntityFramework,其许可协议可从http://go.microsoft.com/fwlink/?LinkId=253898&clcid=0x409 获得。检查包中是否有其他依赖项,这些依赖项可能带有自己的许可协议。您对包和依赖项的使用构成您接受他们的许可协议。如果您不接受许可协议,请从您的设备中删除相关组件。已成功安装“EntityFramework 5.0.0”。已成功添加“EntityFramework 5.0.0”以匹配。

键入“get-help EntityFramework”以查看所有可用的实体框架命令。

PM> Enable-Migrations Get-Package:找不到与参数名称“ProjectName”匹配的参数。在 C:\Users\Dave\Documents\Visual Studio 2010\Projects\Match\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:611 char:40 + $package = Get-Package -ProjectName <<<< $ project.FullName | ?{ $_.Id -eq 'EntityFramework' } + CategoryInfo : InvalidArgument: (:) [Get-Package], ParameterBindingException +fullyQualifiedErrorId : NamedParameterNotFound,NuGet.PowerShell.Commands.GetPackageCommand

EntityFramework 包未安装在项目“Match”上。

采纳答案by SeriousMakc

Just update NuGet to 2.x. EF 5.0 requires it.

只需将 NuGet 更新到 2.x。EF 5.0 需要它。

回答by HockeyJ

Hopefully no-one is as stupid as me, but for the benefit of searchers:

希望没有人像我一样愚蠢,但为了搜索者的利益:

One possibility for this error - In the Package Manager Console, there is a dropdown for 'Default Project'. If this is set incorrectly, you will get The EntityFramework package is not installed on project 'x'. Change the dropdown to your EF project and all is good again.

此错误的一种可能性 - 在包管理器控制台中,有一个“默认项目”下拉菜单。如果设置不正确,您将得到 EntityFramework 包未安装在项目“x”上。将下拉列表更改为您的 EF 项目,一切都恢复正常。

回答by Margus

In my case, restarting the Visual Studio helped.

就我而言,重新启动 Visual Studio 有所帮助。

回答by Nigel Findlater

In my case I had a project that for some reason did not have a Packages.config file. The result was I got the error mesage "The EntityFramework package is not installed on project xxxx".

就我而言,我有一个由于某种原因没有 Packages.config 文件的项目。结果是我收到错误消息“项目 xxxx 上未安装 EntityFramework 包”。

To solve this simply add a Packages.config file and "Install-Package EntityFramework" then works.

要解决这个问题,只需添加一个 Packages.config 文件,然后“Install-Package EntityFramework”即可工作。

回答by Jordec

In my projects I installed EntityFramework on them separately. Even though they all had the same version numbers on each project, it still didn't work. Resulting in the same error you get.

在我的项目中,我分别在它们上安装了 EntityFramework。尽管它们在每个项目上都有相同的版本号,但它仍然不起作用。导致你得到同样的错误。

To fix this, I removed EntityFramework from all my projects and reinstalled it again.

为了解决这个问题,我从所有项目中删除了 EntityFramework 并重新安装了它。

Get-Project -all | Uninstall-Package EntityFramework

Next, you just reinstall it again.

接下来,您只需重新安装它。

Get-Project -all | Install-Package EntityFramework

回答by afshar

I have the same problem. I have added EFCore to a project that has installed EF6. so add-migration xx command performed with EF6 instated of EFCore and I get this error. removing EF6 and restarting Visual Studio solved my problem.

我也有同样的问题。我已将 EFCore 添加到已安装 EF6 的项目中。因此,使用 EFCore 的 EF6 执行 add-migration xx 命令,我收到此错误。删除 EF6 并重新启动 Visual Studio 解决了我的问题。

回答by Ali Yousefi

In my case I install Microsoft.EntityFrameworkCore.Tools package in my project! problem fixed.

就我而言,我在我的项目中安装了 Microsoft.EntityFrameworkCore.Tools 包!问题已解决。

回答by steve

I have just restarted Visual Studio and it worked.

我刚刚重新启动了 Visual Studio 并且它起作用了。

回答by Peter Klein

You will have to install the EF into your project. You can do that via Tools|Manage NuGet Packages, look under 'Installed' and click on 'Manage'. There you will see an option to install EF in your project. After that everything should work and modelchanges will be possible. It can take quite some time (in my case, it did!). Success! Peter

您必须将 EF 安装到您的项目中。您可以通过工具|管理 NuGet 包来实现,在“已安装”下查看并单击“管理”。在那里,您将看到在项目中安装 EF 的选项。之后,一切都应该正常工作,模型更改将成为可能。这可能需要相当长的时间(就我而言,确实如此!)。成功!彼得

回答by Musakkhir Sayyed

Open package manager console and select default project from dropdown in package manager console And Install entity framework using this command in command window.

打开包管理器控制台并从包管理器控制台的下拉列表中选择默认项目并在命令窗口中使用此命令安装实体框架。

install-Package Entityframework