EF 7 .NET Core tools error

.net-core asp.net-core entity-framework-core

Question

I have created a new .NET Core project with dotnet new -t lib command. It's a class library for my EF Context. This is my project.json:

    {
  "version": "1.0.0-*",
  "buildOptions": {
    "debugType": "portable"
  },
  "dependencies": {},
  "frameworks": {
    "netstandard1.6": {
      "dependencies": {
        "NETStandard.Library": "1.6.0",
        "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
        "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
      }
    }
  }
}

When I run dotnet restore command I'm getting this error:

error: Package Microsoft.EntityFrameworkCore.Tools 1.0.0-preview2-final is not compatible with netstandard1.6 (.NETStandard,Version=v1.6). Package Microsoft.EntityFrameworkCore.Tools 1.0.0-preview2-final supports:

How I can use EF Code First with netstandard1.6?

1
11
7/14/2016 6:41:15 PM

Accepted Answer

According to this, The "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final" should be registered in a tools section in project.json:

{
"version": "1.0.0-*",
"description": "Class Library",
"frameworks": {
  "netstandard1.6": {
   "imports": [
     "dnxcore50"
   ]
 }
},

 "dependencies": {
 "NETStandard.Library": "1.6.0",
 "Microsoft.EntityFrameworkCore": "1.0.0",
 "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0"
},
"tools": {
  "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
 }
}

Also it is a good idea to use imports, because some of the EF Core’s dependencies still don't support .NETStandard, but in your case I checked and it works even without imports.

Regarding the Johan B's comment, which states ef tools cannot be used with class libraries for now, it is partly addressed by using --startup-project workaround, for example: dotnet ef --startup-project ../ProjectThatCanRunCommand/ migrations add InitDb, more info: Parameterize directories used by dotnet-ef.

14
7/18/2016 4:54:32 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow