Linux 上的 C# DotNet 实体框架核心迁移错误

问题描述

我在 Linux 上使用 JetBrains Rider。每当我运行 //--- style ----// .mapBoxgl-ctrl-geocoder { font-size: 18px; line-height: 24px; font-family: "Open Sans","Helvetica Neue",Arial,Helvetica,sans-serif; position: relative; background-color: #fff; width: 100%; min-width: 240px; z-index: 1; border-radius: 4px; transition: width .25s,min-width .25s; right: 900px; visibility: hidden; } .mapBoxgl-ctrl-geocoder .show { visibility: visible; } //----- javascript code ------// function search() { let el_mapBoxgl = document.getElementsByClassName('mapBoxgl-ctrl-geocoder')[0]; el_mapBoxgl.className += " show"; } 时,它都会在终端中执行此操作并给我以下错误

dotnet ef migrations add InitialCreate

如果有人知道答案,谢谢!

解决方法

我在 .net 5 Web API 项目中遇到了同样的问题

EF 工具查看 CreateWebHostBuilder 方法并在找不到时返回错误。

directories:

/src 
    |-- /YourPorject.Infrastructure
    |-- /YourPorject.API

public static IHostBuilder CreateWebHostBuilder(string[] args)
{
    return Host.CreateDefaultBuilder(args)
            .ConfigureAppConfiguration((context,config) =>
            {
                config.AddJsonFile(
                    context.HostingEnvironment.ContentRootPath + $"/Config/appsettings-dev.json",false,false);
            })
            .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
}

使用bash创建和更新数据库

    cd src/
    dotnet ef migrations add Init 
    --project YourPorject.Infrastructure/YourPorject.Infrastructure.csproj  
    --startup-project YourPorject.API/YourPorject.API.csproj 
    -o ./Repositories/Migrations/

    cd src/
    dotnet ef database update 
    --project YourPorject.Infrastructure/YourPorject.Infrastructure.csproj 
    --startup-project YourPorject.API/YourPorject.API.csproj

使用这个包(很重要

<ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.8" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.8" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.8" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.8" />
</ItemGroup>