Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MAUI: Add-Migration -> Startup project targets platform 'Android'. The Entity Framework Core .NET Command-line Tools don't support this platform

I want to make an EFCore migration for a MAUI Blazor app. But when using Package Manager or CLI i get an error because startup project targets Android. I do not see this error in the tutorials i am following.

like image 586
Joben Avatar asked Oct 16 '25 13:10

Joben


1 Answers

Migrations cannot be used inside MAUI project directly. The solution is to put the DbContext and Models in a separate Class Library project.

  • Create Class Library Project and create inside it the Models and the DbContext.
  • Reference the class library project from the MAUI project.
  • Add the DbContext in MauiProgram.cs and reference the class library as the Migrations assembly.

When adding migrations, reference the project and startup project as follow:

dotnet ef migrations add Initial --startup-project ..\YourClassLibrary --project ..\YourClassLibrary

Credits to Asaad Iaaly: https://github.com/AssadIaaly/MauiSqlite

like image 106
R44 Avatar answered Oct 18 '25 08:10

R44



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!