3

I follow ASP.NET Core - New Database to use EF in Asp.net Core under VS 2015. But got below error after installing the packages.

Startup project 'src\CoreMVCWebAPI' is an ASP.NET Core or .NET Core project for Visual Studio 2015. This version of the Entity Framework Core Package Manager Console Tools doesn't support these types of projects.

In the document, it says, it need VS 2017 RC, I am wondering whether it is available under VS 2015, or is there any workaround that I could use EF in Asp.net Core, or Ado.net to retrive Data from 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%" ]
  }
}

Source Code:https://github.com/Edward-Zhou/DotNetCore

Edward
  • 28,296
  • 11
  • 76
  • 121
  • Which tools version do you use? There is currently a change happening with VS 2017 that changes the project format, so the newest tooling versions (newer than preview2) will not work with VS 2015. – poke Mar 01 '17 at 11:53
  • Use this [link](https://learn.microsoft.com/en-us/aspnet/core/data/ef-mvc/intro). This demonstrates how to create ASP.NET Core 1.0 MVC web applications using Entity Framework Core 1.0 and Visual Studio 2015. – Sanket Mar 01 '17 at 12:05

3 Answers3

7

You cant use MSBuild (Visual Studio 2017) packages in CSproj (Visual Studio 2015) project. If you will change Microsoft.EntityFrameworkCore.Tools version from 1.1.0-msbuild3-final to for example 1.1.0-preview4-final it should work

Also comments were not allowed in project.json to comply strictly with JSON format. See this announcement github.com/aspnet/Announcements/issues/24 and linked issue for more information/discussion.

J. Doe
  • 2,651
  • 1
  • 13
  • 31
  • Thanks, but it did not work, after only replacing 1.1.0-msbuild3-final with 1.1.0-preview4-final, I got error "Invalid object passed in, ':' or '}' expected. (339)". – Edward Mar 02 '17 at 02:21
  • That error sound like `project.json` problem. Can you show that file? – J. Doe Mar 02 '17 at 11:20
  • I have added it to the original post. Thanks for your help. – Edward Mar 02 '17 at 11:41
  • `project.json` looking good. Do you use `appsettings.json` or other json files? can you post them here? – J. Doe Mar 02 '17 at 11:59
  • I have upload my source code to github, please help to check it. Thanks a lot. – Edward Mar 02 '17 at 12:19
  • Change your `dependencies` section in `project.json` like in my answer – J. Doe Mar 02 '17 at 12:27
  • great, it works with removing all of the "//" in my project.json. It seems Microsoft.EntityFrameworkCore.Tools could not valid comment "//". – Edward Mar 02 '17 at 12:40
  • It was no point at comments but you just forget about `,` after `"Microsoft.EntityFrameworkCore.InMemory": "1.1.0"` (last before `Microsoft.EntityFrameworkCore.Tools`) – J. Doe Mar 02 '17 at 12:48
  • Not exactly, I did not miss ",". Below would not work ` "Microsoft.EntityFrameworkCore.InMemory": "1.1.0", //Test, "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0", "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final"`, removing "//Test," makes it work. – Edward Mar 02 '17 at 12:58
  • Good to know. `project.json` was always bugged so i hope new XML (MSBuild) will work perfect – J. Doe Mar 02 '17 at 13:05
  • Comments were not allowed in project.json to comply strictly with JSON format. See this announcement https://github.com/aspnet/Announcements/issues/24 and linked issue for more information/discussion. – Smit Mar 02 '17 at 19:23
0

You need a reference to EntityFrameWorkCore.Tools.DotNet in the Tools Section as below

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

For more info, look at my answer here.

The term "Add-Migration" is not recognized

Community
  • 1
  • 1
Francis
  • 1,798
  • 1
  • 26
  • 32
0

You must install an earlier version of EF Core, due to compatibility of .NET Core 2.0 with Visual Studio 2015.

I selected EF Core 1.1.5 version and got the message: "Successfully installed 'Microsoft.EntityFrameworkCore.Tools 1.1.5'"

Greetings, Andres!

Andy
  • 751
  • 1
  • 12
  • 25