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

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

问题描述

我想按照本教程使用 EF Core 创建一个控制台应用程序:

怎么了?

更新

语句 dotnet restore 有效而 dotnet-ef --help 根本无效.

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

解决方案

正如评论中提到的一些人,Microsoft.EntityFrameworkCore.Tools需要添加到tools代码> project.json 的部分.

我已经使用最新(2016 年 7 月)版本的 EF Core 和工具包测试了这个 project.json,并且可以正常工作:

<代码>{构建选项":{emitEntryPoint":真},依赖关系":{"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",Microsoft.EntityFrameworkCore.Design":{"version": "1.0.0-preview2-final",类型":构建"},Microsoft.NETCore.App":{"类型": "平台",版本":1.0.0"}},构架": {netcoreapp1.0":{}},工具": {"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"},版本":1.0.0-*"}

要使用它,请从项目文件夹的内部执行以下命令:

λ dotnet 恢复日志:恢复在 2810 毫秒内完成.λ dotnet ef --help为 .NETCoreApp 编译 EfCoreTester2,版本=v1.0编译成功.0 警告0 错误已用时间 00:00:01.7208394实体框架 .NET Core CLI 命令 1.0.0-preview2-21431用法:dotnet ef [选项] [命令]选项:-h|--help 显示帮助信息-v|--verbose 启用详细输出--version 显示版本信息(... 等等)

起初,我得到 No executable found matching command "dotnet-ef" 直到我意识到你必须从项目文件夹内执行命令 (srcprojectName代码>在我的情况下).如果您尝试从解决方案根目录执行此操作,它将无法正常工作.

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 'srcAppEf'. 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 (srcprojectName in my case). If you try to do it from the solution root directory, it won't work.

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

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