We have been trying to run EF Core Migration in .Net Standard 1.6 class library, but it has been failing. But same passes very well in .Net Core 1.1 class library.
Is EF Migration supported in .NET STANDARD?
The documentation covers this case as know issue/limitation when the DbContext
is placed inside an netstandardx.y
Class Library.
Workaround 1 - Use an app as the startup project
If you have an existing .NET Core App or .NET Framework App (including an ASP.NET Core Web Application), you can use it as the startup project. If not, you can create a new one just for use with the .NET Command Line Tools. Specify a startup project that is a "runnable app." Example: console
dotnet ef migrations list --startup-project ../MyConsoleApp/
Workaround 2 - Cross-target a runnable framework
Add an additional target framework to the class library project. This can a version of either .NET Core App or .NET Framework. To make the project a .NET Core App, add the "netcoreapp1.0" framework to project like in the sample below: XML
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFrameworks>netcoreapp1.0;netstandard1.4</TargetFrameworks> </PropertyGroup> </Project>
When targeting .NET Framework, ensure you project targets version 4.5.1 or newer. XML
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFrameworks>net46;netstandard1.4</TargetFrameworks> </PropertyGroup> </Project>