I have created an asp.net core RC2 (.NET 4.61 framework) project.
Then I have created another "DataProvider" nuget class library (.NET core) with Entity Framework references and changed the framework
in the project.json
settings to "net461":{}
.
The reason why I did not create a common c# class library because it has no project.json but I need that to setup stuff like:
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.EntityFrameworkCore": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore.Tools": {
"type": "build",
"version": "1.0.0-preview1-final"
}
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": {
"imports": [ "portable-net451+win8" ],
"version": "1.0.0-preview1-final"
}
},
"frameworks": {
"net461": {
"buildOptions": {
"emitEntryPoint": true
}
}
}
}
The DataProvider project has my DbContext class.
Thus I go to the command line to the DataProvider directory and execute:
dotnet ef migrations add Init
Then I get this error:
This preview of Entity Framework tools does not support targeting class library projects in ASP.NET Core and .NET Core applications. See http://go.microsoft.com/fwlink/?LinkId=798221 for details and workarounds.
I do NOT want to put my DbContext into the asp.net core rc2 project !!!
I clicked that link to find more about that workarounds, but there is actually nothing helpfull until I found that link:
https://github.com/aspnet/EntityFramework.Docs/blob/master/docs/cli/dotnet.rst
Here are 2 workarounds introduced due to this error I had before:
workaround 1 did not work ("To make the project a .NET Core App, add the "netcoreapp1.0" framework to project.json along with the other settings in the sample below:")
This is how I changed then the project.json
{
"frameworks": {
"netcoreapp1.0": {
"imports": [ "portable-net451+win8" ],
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-*"
},
"Microsoft.EntityFrameworkCore": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore.Tools": {
"type": "build",
"version": "1.0.0-preview1-final"
}
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": {
"imports": [ "portable-net451+win8" ],
"version": "1.0.0-preview1-final"
}
}
}
}
}
=> Because after many nugets get installed and I rebuild then I also have to add a program.cs which I added etc.. Then I rerun the "dotnet ef migrations add Init" on the CMD getting this error: No executable found matching command "dotnet-ef"
workaround 2 did not work: ("To make a desktop .NET app, ensure you project targets "net451" or newer (example "net461" also works) and ensure the build option "emitEntryPoint" is set to true.")
=> Because I get compile exception, that program.cs has no Main method.
Ok, I have a class library this has never a program.cs ... Then I added the program.cs with the static Main method. Now the project compiles, but when I rerun the "dotnet ef migrations add Init" on the CMD I get the same error as before !!!
What should I do to make the execution of "dotnet ef migrations add Init" work?