![](/img/trans.png)
[英]ASP.NET Core (3.1) with EF Core Migrations and IHttpContextAccessor
[英]On Mac M1 machine - Not able to run EF core Migrations Add ,Update in Asp.Net Core 3.1
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.
我通過 NuGet Package 成功添加了 EntityFrameworkCore(5.0.11)。 我的 Mac 上的 sdk 和運行時安裝詳細信息是:
.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.
現在的問題是我無法運行 EFcore 遷移添加初始,通過實體框架更新數據庫。 我到處搜索,但每當我執行這些命令時,我都會收到以下錯誤:
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.
我確實安裝了上述框架,但那是 x64。 而且 EF 命令仍然不起作用,我無法更新數據庫。 有什么解決辦法嗎? EFCore 可以在 Mac M1 機器上運行嗎?
更新
這將永久解決問題:
dotnet tool uninstall dotnet-ef -g
dotnet tool install dotnet-ef -a arm64 -g
也可以在本地安裝 EF 工具
CD 到您的源目錄並執行以下操作:
dotnet new tool-manifest
dotnet tool install dotnet-ef
通過這種方式,它可以與.Net 5/6 arm64 一起使用。
arm64 版本安裝程序中存在引用 x64 版本的 EF Core 的錯誤。
原因是 ef 工具目前無法找到正確的拱門。 一種解決方法是強制 ef 工具使用在您的機器上找到的最新運行時。
export DOTNET_ROLL_FORWARD=LatestMajor
導出上述環境變量並再次運行dotnet ef xxx
。
嘗試從此鏈接手動安裝正確的 SDK 版本。
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
然后,
/usr/local/share/dotnet/x64/dotnet ef migrations add initialCreate -s ../API -o Migrations
您可以使用這篇文章https://dev.to/smiththe_4th/use-multiple-net-sdk-cli-commands-on-mac-m1-64j縮短路徑
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.