Reputation: 71
I have recently got a Mac M1, I have to build a Microservice based Web API application on Asp.net Core using EF & SQL Server.
I added EntityFrameworkCore(5.0.11) through NuGet Package successfully. The sdk & runtime installed details on my Mac is:
.NET SDKs installed: - 6.0.101 .NET runtimes installed: - Microsoft.AspNetCore.App 6.0.1 - Microsoft.NETCore.App 6.0.1
Firstly , I was not able to install SQL Server 2019 on Mac but after searching I found a solution for that by installing SQL Edge on Docker & connecting to Azure Data Studio and it's working fine.
Now the problem is I am not able to run EFcore migration add initial, Update Database through Entity Framework. I searched everywhere but whenever I am executing these command, I am getting following error:
Build started... Build succeeded. It was not possible to find any compatible framework version The framework 'Microsoft.AspNetCore.App', version '3.1.0' (arm64) was not found. - The following frameworks were found: 6.0.1 You can resolve the problem by installing the specified framework and/or SDK. The specified framework can be found at: - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=3.1.0&arch=arm64&rid=osx.12-arm64.
I did install the above framework but that is x64. And still EF command are not working and I am not able to update the database. Is there any solution for this? Does EFCore work on Mac M1 machines?
Upvotes: 6
Views: 4845
Reputation: 786
Update
This fixes the problem permanently:
dotnet tool uninstall dotnet-ef -g
dotnet tool install dotnet-ef -a arm64 -g
You can also install EF tool locally
CD to your source directory and do this:
dotnet new tool-manifest
dotnet tool install dotnet-ef
In this way, it works with the .Net 5/6 arm64.
There's a bug in the arm64 version installer that references the x64 version of EF Core.
Upvotes: 8
Reputation: 135
You need to use the sdk version for your cli,.NET 5 and below installs in a different directory and from your output looks like you cli points to .NET 6. You should install the ef tools locally like so
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local dotnet-ef --version 5.0.15
then,
/usr/local/share/dotnet/x64/dotnet ef migrations add initialCreate -s ../API -o Migrations
You can shorten the path by using this article https://dev.to/smiththe_4th/use-multiple-net-sdk-cli-commands-on-mac-m1-64j
Upvotes: 0
Reputation: 1314
The reason is that ef tool is not able to find the correct arch for now. A workaround is to force ef tool to use the latest runtime found on your machine.
export DOTNET_ROLL_FORWARD=LatestMajor
export the above env var and run dotnet ef xxx
again.
Upvotes: 7