【问题标题】:EF Core Tools not working on dotnet core 3 preview 4EF Core Tools 不适用于 dotnet core 3 preview 4
【发布时间】:2020-06-15 16:22:45
【问题描述】:

我正在尝试使用 dotnet core 3 preview 4 开发一些 Web API。我熟悉 dotnet core 及其库,如 EF core 和 Identity 等。但是现在有了版本 3 preview 4,Microsoft.EntityFrameworkCore.Tools 可以不起作用,命令dotnet ef migrations add ... 告诉此消息:

找不到命令'dotnet ef',请运行以下命令 安装

dotnet tool install --global dotnet-ef

csproj文件是这样的:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0-preview4-19216-03" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0-preview4.19216.3" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.0.0-preview4.19216.3" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0-preview4.19216.3"/>
  </ItemGroup>

</Project>

我也试过dotnet tool install --global dotnet-ef,但没有解决我的问题。由于版本 3 预览版 4 是新发布的,因此我在官方或第三方网站上找不到任何相关文档。

【问题讨论】:

    标签: entity-framework .net-core command-line-interface


    【解决方案1】:

    编辑:

    此时 dotnet core 3 不再是预览版,因此请相应地选择我们的版本。 (Check version)


    首先确定,

    1. 您正在使用 .NET Core SDK 3.0 预览版,输入 dotnet --info 并看到有这样一行,
    .NET Core SDKs installed:
      3.0.100-preview4-011223 [C:\Program Files\dotnet\sdk]
    
    1. 您在项目上运行dotnet restore
    2. 您已cded 到项目的 (*.csproj) 目录

    使用 Entity Framework Core 3.0 Preview 4,dotnet-ef 工具不再是 .NET Core SDK 的一部分。使用卸载稳定版dotnet-ef工具(此时为2.2.4),

    dotnet tool uninstall --global dotnet-ef
    

    然后安装预览版或最新稳定版,(Check version)

    dotnet tool install --global dotnet-ef --version 3.0.0-preview4.19216.3
    

    之后dotnet ef 应该可以正常工作了。

    【讨论】:

      【解决方案2】:

      .NET Core 3.0 引入Local Tools

      本地工具类似于全局工具,但与磁盘上的特定位置相关联。本地工具无法在全球范围内使用,而是作为 NuGet 包分发。

      dotnet Core 以及 EF Core 正在快速发展。在不同的 dotnet 版本中很容易拥有多个项目/解决方案。使用本地工具,您可以按项目配置特定版本的工具。

      按项目配置工具的步骤:

      dotnet new tool-manifest  
      #executing this at sln level (or with your projecte) a new .config file is created
      
      #check lasts versions at:
      #https://www.nuget.org/packages/dotnet-ef/
      
      dotnet tool install --local dotnet-ef --version 3.1.4
      #this will configure dotnet ef tool
      
      dotnet ef
      #should run at this point
      

      此时您的 ef migrations/database 命令必须运行。

      当人们克隆你的 repo 时应该运行:

      dotnet tool restore
      

      【讨论】:

      • 最后一行不应该是dotnet dotnet-ef吗?如果我错了,请纠正我
      • 跳过第二个命令中的 --version 参数以使用最新版本
      【解决方案3】:
      dotnet tool install -g dotnet-ef --version 3.0.0-preview4.19216.3
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-10-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-05-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多