没有安装Microsoft.EntityFrameworkCore.Tools,ASP.net核心

时间:2017-04-18 13:36:04

标签: entity-framework .net-core

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

我希望vs2015可以为我创建数据库(代码首次迁移?)。我已经安装了包EntityFrameworkCore及其工具,然后为vs2015安装Add-Migration来创建数据库。我的sqlserver是在本地安装的,所以没有网络问题。 Add-Migration在安装成功时遇到了一个奇怪的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"
        }
    }
}

我试图恢复软件包,重建项目但没有任何帮助。

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

enter image description here

我的课程尽可能简单:

Fruit.cs

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");
        }
    }
}

我认为这与我的班级无关,但无论如何我都列出了。我试图将工具移动到json文件中自己的部分,如其他帖子所示,但我仍然得到同样的错误。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

如果您检查最后一行错误,请说明public interface Set<U> {...} public interface SetExtended<U> extends Set<U> {...} public abstract class AbstractSetExtended<U> implements SetExtended<U>{...} public class Set1<U> extends AbstractSetExtended<U> {...} public class Set2<U> extends AbstractSetExtended<U> {...}

Add 'Microsoft.EntityFrameworkCore.Tools' to the 'tools' section in project.json中,您只添加了依赖关系。您还需要添加工具部分。请参阅以下示例 -

project.json

有关详细信息,请参阅升级工具包部分here