VS 2015中的Asp.net核心EF

时间:2017-03-01 11:48:40

标签: asp.net-core entity-framework-core

我跟随ASP.NET Core - New Database在VS 2015下使用Asp.net Core中的EF。但是在安装软件包后得到以下错误。

  

启动项目'src \ CoreMVCWebAPI'是ASP.NET核心或.NET核心   Visual Studio 2015的项目。此版本的实体框架   核心软件包管理器控制台工具不支持这些类型   项目

在文档中,它说,它需要VS 2017 RC,我想知道它是否在VS 2015下可用,或者是否有任何解决方法我可以在Asp.net Core或Ado.net中使用EF来检索数据来自SQL DataBase。

PM> Add-Migration MyFirstMigration
Invalid object passed in, ':' or '}' expected. (339): {
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.1",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    //Dependence for MVC
    "Microsoft.AspNetCore.Mvc": "1.1.1",
    "Microsoft.AspNetCore.StaticFiles": "1.1.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
    "Microsoft.Extensions.Configuration.Json": "1.1.0",
    //Dependence for EF
    "Microsoft.EntityFrameworkCore":"1.1.0",
    "Microsoft.EntityFrameworkCore.InMemory": "1.1.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
    "Microsoft.EntityFrameworkCore.Tools":"1.1.0-preview4-final"
    //Dependence for EF with SQL, this is avalible under VS 2017 RC
    //"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
    //Entity Framework commands to maintain the database
    //"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview4-final"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    //used for Razor pages which are compiled at runtime,and the compiler needs access to reference assemblies,
    //to make sure it compiles correctly
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "web.config"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

源代码:https://github.com/Edward-Zhou/DotNetCore

3 个答案:

答案 0 :(得分:7)

您无法在MSBuild(Visual Studio 2015)项目中使用CSproj(Visual Studio 2017)程序包。如果您要将Microsoft.EntityFrameworkCore.Tools版本从1.1.0-msbuild3-final更改为例如1.1.0-preview4-final,则应该有效

同样,project.json中的注释不允许严格遵守JSON格式。有关更多信息/讨论,请参阅此公告github.com/aspnet/Announcements/issues/24和链接问题。

答案 1 :(得分:0)

您需要在工具部分中引用EntityFrameWorkCore.Tools.DotNet,如下所示

" Microsoft.EntityFrameworkCore.Tools.DotNet":" 1.0.0"

有关详细信息,请在此处查看我的答案。

The term "Add-Migration" is not recognized

答案 2 :(得分:0)

由于.NET Core 2.0与Visual Studio 2015的兼容性,您必须安装早期版本的EF Core。

我选择了EF Core 1.1.5版本并收到消息:“已成功安装'Microsoft.EntityFrameworkCore.Tools 1.1.5'”

问候,安德烈斯!