Entity framework Microsoft.EntityFrameworkCore.Tools未安装,ASP.net core

Entity framework Microsoft.EntityFrameworkCore.Tools未安装,ASP.net core,entity-framework,.net-core,Entity Framework,.net Core,我正在创建一个简单的控制台应用程序(.netcore)应用程序,在这里我定义了一个名为fruit的类和一个名为FruitDbContext的dbcontext。我在这个示例中使用了VS2015和SQL Server 我希望vs2015能为我创建数据库(代码优先迁移?)。我已经安装了包EntityFrameworkCore及其工具,然后为vs2015添加迁移以创建数据库。我的sqlserver安装在本地,因此没有网络问题。添加迁移在成功安装时遇到一个奇怪的Microsoft.EntityFrame

我正在创建一个简单的控制台应用程序(.netcore)应用程序,在这里我定义了一个名为fruit的类和一个名为FruitDbContext的dbcontext。我在这个示例中使用了VS2015和SQL Server

我希望vs2015能为我创建数据库(代码优先迁移?)。我已经安装了包EntityFrameworkCore及其工具,然后为vs2015添加迁移以创建数据库。我的sqlserver安装在本地,因此没有网络问题。添加迁移在成功安装时遇到一个奇怪的Microsoft.EntityFrameworkCore.Tools未安装

PM> Install-Package Microsoft.EntityFrameworkCore.SqlServer
Retrieving package 'Microsoft.EntityFrameworkCore.SqlServer 1.1.1' from 'nuget.org'.
  GET https://www.nuget.org/api/v2/Packages(Id='Microsoft.EntityFrameworkCore.SqlServer',Version='1.1.1')
  OK https://www.nuget.org/api/v2/Packages(Id='Microsoft.EntityFrameworkCore.SqlServer',Version='1.1.1') 43ms
  GET https://www.nuget.org/api/v2/package/Microsoft.EntityFrameworkCore.SqlServer/1.1.1
  OK https://www.nuget.org/api/v2/package/Microsoft.EntityFrameworkCore.SqlServer/1.1.1 103ms
Installing Microsoft.EntityFrameworkCore.SqlServer 1.1.1.
Installing NuGet package Microsoft.EntityFrameworkCore.SqlServer.1.1.1.
Successfully installed 'Microsoft.EntityFrameworkCore.SqlServer 1.1.1' to ConsoleApp1
Executing nuget actions took 1.01 sec
Time Elapsed: 00:00:01.3928695
PM> Install-Package microsoft.EntityFrameworkCore.Tools
Retrieving package 'Microsoft.EntityFrameworkCore.Tools 1.1.0' from 'nuget.org'.
  GET https://www.nuget.org/api/v2/Packages(Id='Microsoft.EntityFrameworkCore.Tools',Version='1.1.0')
  OK https://www.nuget.org/api/v2/Packages(Id='Microsoft.EntityFrameworkCore.Tools',Version='1.1.0') 79ms
  GET https://www.nuget.org/api/v2/package/Microsoft.EntityFrameworkCore.Tools/1.1.0
  OK https://www.nuget.org/api/v2/package/Microsoft.EntityFrameworkCore.Tools/1.1.0 105ms
Installing Microsoft.EntityFrameworkCore.Tools 1.1.0.
Installing NuGet package Microsoft.EntityFrameworkCore.Tools.1.1.0.
Successfully installed 'Microsoft.EntityFrameworkCore.Tools 1.1.0' to ConsoleApp1
Executing nuget actions took 554.65 ms
Time Elapsed: 00:00:00.8128143
PM> Add-Migration InitialMigration
Cannot execute this command because 'Microsoft.EntityFrameworkCore.Tools' is not installed in project 'src\ConsoleApp1'. Add 'Microsoft.EntityFrameworkCore.Tools' to the 'tools' section in project.json. See http://go.microsoft.com/fwlink/?LinkId=798221 for more details.
我的Json文件

{
    "version": "1.0.0-*",
    "buildOptions": {
        "emitEntryPoint": true
    },

    "dependencies": {
            "Microsoft.EntityFrameworkCore.SqlServer": "1.1.1",
            "Microsoft.EntityFrameworkCore.Tools": "1.1.0",
            "Microsoft.NETCore.App": {
                "type": "platform",
                "version": "1.0.1"
            }
    },
    "frameworks": {
        "netcoreapp1.0": {
            "imports": "dnxcore50"
        }
    }
}
我曾试图恢复包,重建项目,但没有任何帮助

这是我的项目结构,表明我没有做任何花哨的事

我的课程尽可能简单:

水果公司

namespace ConsoleApp1.Entity
{
    public class Fruit
    {
        public string ID { get; set; }
        public string FruitName { get; set; }
        public string FruitColor { get; set; }
    }
}
FruitDbContext.cs

using Microsoft.EntityFrameworkCore;

namespace ConsoleApp1.Entity
{
    public class FruitDbContext : DbContext
    {
        public DbSet<Fruit> Fruits { get; set; }
        protected override void OnConfiguring(DbContextOptionsBuilder optionBuilder)
        {
            optionBuilder.UseSqlServer(@"Data Source = xxx; Database=Fruitdb; Integrated Security = True; Connect Timeout = 15; Encrypt = False; TrustServerCertificate = True; ApplicationIntent = ReadWrite; MultiSubnetFailover = False");
        }
    }
}
使用Microsoft.EntityFrameworkCore;
名称空间ConsoleApp1.Entity
{
公共类fructDBContext:DbContext
{
公共数据库集{get;set;}
配置时受保护的覆盖无效(DBContextOptionBuilder optionBuilder)
{
optionBuilder.UseSqlServer(@“数据源=xxx;数据库=Fruitdb;集成安全=True;连接超时=15;加密=False;信任服务器证书=True;应用内容=ReadWrite;多子网故障转移=False”);
}
}
}
我想这与我的课程无关,但我还是列出了。我曾尝试将这些工具移动到json文件中自己的部分,正如其他帖子中所建议的那样,但仍然会出现相同的错误


有什么想法吗?

如果您检查最后一行错误,它会说-
将“Microsoft.EntityFrameworkCore.Tools”添加到project.json的“Tools”部分

project.json
中,您只添加了依赖项。您还需要添加工具部分。参考下面的示例-

{
    "version": "1.0.0-*",
    "buildOptions": {
        "emitEntryPoint": true
    },

    "dependencies": {
            "Microsoft.EntityFrameworkCore.SqlServer": "1.1.1",
            "Microsoft.EntityFrameworkCore.Tools": "1.1.0",
            "Microsoft.NETCore.App": {
                "type": "platform",
                "version": "1.0.1"
            }
    },
    "tools": {
      ....
      "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4"  << Add respective version here
      ....
    },
    "frameworks": {
        "netcoreapp1.0": {
            "imports": "dnxcore50"
        }
    }
}
{
“版本”:“1.0.0-*”,
“构建选项”:{
“emittentrypoint”:真
},
“依赖项”:{
“Microsoft.EntityFrameworkCore.SqlServer”:“1.1.1”,
“Microsoft.EntityFrameworkCore.Tools”:“1.1.0”,
“Microsoft.NETCore.App”:{
“类型”:“平台”,
“版本”:“1.0.1”
}
},
“工具”:{
....

“Microsoft.EntityFrameworkCore.Tools.DotNet”:“1.1.0-preview4”我在json中手动添加了工具,这次它抱怨“没有找到匹配命令的可执行文件”DotNet ef"我不记得发过command@user1205746请检查我的更新答案。此外,您可以参考“升级工具包”部分。您已经尝试了您的建议,并将该包升级到1.1,甚至已安装。NetCore 1.1 SDK。出现了另一个错误:术语“添加迁移”未被识别为cmdlet、函数、脚本文件的名称r可操作的程序。@user1205746如中所述,运行
Add Migration InitialCreate
来构建迁移以创建模型的初始表集。如果收到一个错误,说明
术语“Add Migration”无法识别为cmdlet的名称,请关闭并重新打开Visual Studio。