软件包pipe理器控制台启用 – 迁移仅在特定VS项目中使用CommandNotFoundException

我试图在一个新的项目中运行命令“Enable-Migrations”,并得到以下消息:

PM> Enable-Migrations The term 'Enable-Migrations' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verif y that the path is correct and try again. At line:1 char:18 + Enable-Migrations <<<< + CategoryInfo : ObjectNotFound: (Enable-Migrations:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException 

但在所有其他项目中,命令运行得很好。

为什么发生这种情况?

顺便说一下,我正在使用VS2010 Professional SP1

编辑:我重新安装commmand: 安装包EntityFramework -IncludePrerelease和问题消失了。

只是简单地重新启动Visual Studio为我工作。 无需安装软件包等

我重新安装了命令:Install-Package EntityFramework -IncludePrerelease,问题就消失了。

pipe理员权限重新启动Visual Studio解决了我的问题。

让您以pipe理员身份运行Visual Studio。

首先“Install-Package EntityFramework -Include预发行”,然后以pipe理员身份重新启动Visual Studio一起工作。

在Visual Studio 2012中,我有同样的错误。 不得不卸载NuGet(工具>扩展和更新>安装>全部:NuGet包pipe理器:卸载button)。 然后closuresVisual Studio。 然后重新打开Visual Studio并重新安装NuGet(工具>扩展和更新>联机> Visual Studio图库:NuGet程序包pipe理器:下载button)。 然后在以下窗口中:单击安装button,然后单击closuresbutton。 然后closures并重新打开Visual Studio。

这个问题正在发生,因为我们没有enity框架。 请使用下面的命令安装entity framework。

 Install-Package EntityFramework -IncludePrerelease 

安装完成后,在包pipe理器控制台默认项目下拉菜单中select项目。

并确保项目中至less有一个类是从数据上下文inheritance的

否则使用下面的类

 public class MyDbContext : DbContext { public MyDbContext() { } } 

如果我们不这样做,我们会得到另一个错误

No context type was found in the assembly

完成所有这些事情后,您可以运行启用迁移。

我有同样的问题,我发现这是因为项目path中的一些字符像[或]我正确的项目path,它工作正常!

什么解决了这个症状(VS2013)是卸载,然后用Nuget重新安装EF软件包。 csproj文件的差异改变了这个…

 <Reference Include="EntityFramework"> <HintPath>..\packages\EntityFramework.6.1.1\lib\net45\EntityFramework.dll</HintPath> </Reference> 

…进入这个…

 <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>..\packages\EntityFramework.6.1.1\lib\net45\EntityFramework.dll</HintPath> </Reference> 

我还不完全明白为什么,但是至less起作用了。

在.NET Core中,通过在包pipe理器控制台中input以下内容,可以达到与接受的答案中所述的相同的分辨率:

 Install-Package EntityFramework.Core -Pre 

由于我已经有了迁移文件夹,我重新启动了Visual Studio,并在包pipe理器控制台中运行了Update-Database -verbose。 这对我有效

在VS 2013中,尝试安装UPDATE 1(RC1)并解决问题。

我在解决scheme中有多个项目,但我有正确的默认项目集,所以我认为它应该工作。

最后,我不得不在命令中添加-StartupProject MyProjectName选项

Enable-Migrations -EnableAutomaticMigrations

这些解决scheme都不适合我。 我的解决scheme是删除packages/EntityFramework.6.1.3Restore NuGet Packages

我注意到packages/EntityFramework.6.1.3/tools/EntityFramework.psd1丢失了,所以这是一个可能的原因。 尽pipe我不知道它是如何被移除的。

检查configuration节“entityFramework”是否存在并在.config文件中描述

 <configSections> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/></configSections> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/> <providers> <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/> </providers> </entityFramework> 

检查解决scheme资源pipe理器窗口中是否打开项目。

这可能是你的问题的原因。