添加迁移失败,因为未安装EntityFrameworkCore.Tools [英] Add-Migration fails because EntityFrameworkCore.Tools is not installed

查看:1177
本文介绍了添加迁移失败,因为未安装EntityFrameworkCore.Tools的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过以下教程创建一个带有EF Core的控制台应用程序:



你可以看到,该语句在项目文件夹中执行。

解决方案

由于少数人在评论中提到, Microsoft.EntityFrameworkCore.Tools 需要添加到project.json的工具部分。



我已经测试了这个项目。 json与最新的(2016年7月)版本的EF Core和工具包,它的工作原理:

  {
buildOptions:{
emitEntryPoint:true
},
dependencies:{
Microsoft.EntityFrameworkCore.SqlServer:1.0.0,
Microsoft.EntityFrameworkCore.Design:{
version:1.0.0-preview2-final,
type:build
},
Microsoft.NETCore.App:{
type:platform,
version:1.0.0
}
},
框架:{
netcoreapp1.0:{}
},
工具:{
Microsoft.EntityFrameworkCore.Tools:1.0.0-preview2-final
},
version:1.0.0- *
}

要使用它,请从里面的项目文件夹执行这些命令:

 λdotnet restore 
log:恢复完成在2810ms。

λdotnet ef --help
编译.NETCoreApp的EfCoreTester2,版本= v1.0
编译成功。
0警告
0错误
时间逝去00:00:01.7208394

实体框架.NET Core CLI命令1.0.0-preview2- 21431
用法:dotnet ef [options] [命令]
选项:
-h | --help显示帮助信息
-v | --verbose启用详细输出
--version显示版本信息
(...等)

起初,我得到没有可执行文件找到匹配命令dotnet-ef,直到我意识到你必须从项目文件夹内执行命令( src\ projectName 在我的情况)。如果您尝试从解决方案根目录中执行此操作,将无法正常工作。


I want to create a console application with EF Core by following this tutorial: http://ef.readthedocs.io/en/latest/platforms/full-dotnet/new-db.html.

My problem is, I cannot execute the statement

Add-Migration 

as described in the tutorials. It shows me:

PM> Add-Migration MyFirstMigration
Cannot execute this command because 'Microsoft.EntityFrameworkCore.Tools' is not installed in project 'src\AppEf'. Add 'Microsoft.EntityFrameworkCore.Tools' to the 'tools' section in project.json. See http://go.microsoft.com/fwlink/?LinkId=798221 for more details.

All added assemblies:

What is wrong?

Update

The statement dotnet restore works and dotnet-ef --help does not work at all.

And you can see, the statement is execute in project folder.

解决方案

As a few people mentioned in the comments, Microsoft.EntityFrameworkCore.Tools needs to be added to the tools section of project.json.

I've tested this project.json with the latest (July 2016) versions of EF Core and the tooling packages, and it works:

{
    "buildOptions": {
    "emitEntryPoint": true
  },
  "dependencies": {
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
    "Microsoft.EntityFrameworkCore.Design": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0"
    }
  },
  "frameworks": {
    "netcoreapp1.0": {}
  },
  "tools": {
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
  },
  "version": "1.0.0-*"
}

To use it, execute these commands from inside the project folder:

λ dotnet restore
log  : Restore completed in 2810ms.

λ dotnet ef --help
Compiling EfCoreTester2 for .NETCoreApp,Version=v1.0                                                                            
Compilation succeeded.                                                                                                          
    0 Warning(s)                                                                                                                
    0 Error(s)                                                                                                                  
Time elapsed 00:00:01.7208394                                                                                                   

Entity Framework .NET Core CLI Commands 1.0.0-preview2-21431
Usage: dotnet ef [options] [command]
Options:
  -h|--help                      Show help information
  -v|--verbose                   Enable verbose output
  --version                      Show version information
(... etc)

At first, I was getting No executable found matching command "dotnet-ef" until I realized that you have to execute the commands from inside the project folder (src\projectName in my case). If you try to do it from the solution root directory, it won't work.

这篇关于添加迁移失败,因为未安装EntityFrameworkCore.Tools的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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