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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With