EF Core 迁移过程遇到EF Core tools version版本不相符的解决方案

如果你使用命令:

PM> add-migration Inital

提示如下信息时:

The EF Core tools version '2.1.1-rtm-30846' is older than that of the runtime '2.1.4-rtm-31024'

解决方法大致一下几种:

第一


最近在跟着官方的文档学习 .NET Core 。 在写 “创建 Razor 页面 Web 应用” Demo 中的——“添加模型”这一篇的教程,“添加初始迁移”中遇到 “The EF Core tools version '2.1.1-rtm-30846' is older than that of the runtime '2.1.3-rtm-32065'. Update the tools for the latest features and bug fixes.”这样的问题。

这个问题是用 PMC 命令做“初始迁移”的时候出现的,找了很多方法都不行,也看了本机安装的 .NET Core 的版本(dotnet --version,dotnet --info)。

最后解决办法: 项目文件夹下使用 .NET Core CLI 命令: dotnet ef migrations add Initial dotnet ef database update 完成后运行可以了

第二


编辑你的<项目名称>.csproj文件

添加以下内容

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

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.4" />
    <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.6" />
  </ItemGroup>

</Project>

然后运行命令:

PM> Update-Package

posted @ 2018-11-25 23:02  duanyong  阅读(4067)  评论(3编辑  收藏  举报