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?
Adding a Migration So, firstly, you need to create a migration. Open the Package Manager Console from the menu Tools -> NuGet Package Manager -> Package Manager Console in Visual Studio and execute the following command to add a migration.
EF core doesn't support automatic migrations . So you have to do it manually.
EF 6 supports . NET Standard 2.1, which is currently supported by . NET Core 3.0 or later - no . NET Framework version.
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>
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