Entity framework core 需要更新EF核心工具

Entity framework core 需要更新EF核心工具,entity-framework-core,Entity Framework Core,当我在VS 2017 Package Manager控制台中使用dotnet ef工具时,我收到一条关于需要更新ef核心工具的警告消息: PM> dotnet ef migrations list -s ../RideMonitorSite The EF Core tools version '2.1.1-rtm-30846' is older than that of the runtime '2.1.2-rtm-30932'. Update the tools for the lat

当我在VS 2017 Package Manager控制台中使用dotnet ef工具时,我收到一条关于需要更新ef核心工具的警告消息:

PM> dotnet ef migrations list -s ../RideMonitorSite

The EF Core tools version '2.1.1-rtm-30846' is older than that of the runtime '2.1.2-rtm-30932'. Update the tools for the latest features and bug fixes.
20180831043252_Initial
但我的csproj文件有以下条目:

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.1.2" />
  </ItemGroup>

那么我该如何更新这些工具呢?顺便说一句,我在其他答案中看到,过期的global.json文件可能会导致此问题。但是我在解决方案中的任何地方都没有global.json文件。

安装新的.NET Core SDK v2.1.401版本,然后再次检查>dotnet ef--version。我有同样的问题,在我的情况下,这是有效的。另外,您不需要添加Microsoft.EntityFrameworkCore.Tools.DotNet。

我将此问题提交给了。事实证明,这是当前工具或nuget包中的一个错误,当您创建一个EF Core支持的AspNet Core站点时,这些工具或nuget包会被加载。它的目标是在未来的版本中修复

目前,解决办法只是忽略警告


另外还提供了另一种解决方法,包括调整csproj文件以明确定义AspNet核心元包的版本——在我写这篇文章时,它是2.1.3版本——但我无法让这种方法起作用;我仍然不断收到警告消息。

我找不到如何具体更新包,但在包管理器控制台中,我运行了“更新包”。它运行并更新了项目中引用的所有包,包括EF核心工具。这可能不适合您,因为这可能会更新您不想要的包

我的解决方案是从microsoft安装工具dotnet ef。它使用相同的命令,但没有警告。更改是使用dotnet ef而不是dotnet ef

如果已经安装了dotnet ef,则使用
dotnet工具更新--global dotnet ef--version n.n.n
(n.n.n您要更新的版本)

  • 忽略这个问题
  • 不要更新您的
  • 在我的例子中,我继续使用“更新数据库-上下文MyElementContext”,现在一切正常
我在Dino Esposito的《编程ASP.NET核心》一书中发现了这一点

'注意此版本的CLI工具与应用程序将使用的.NET核心运行时版本不同。项目文件中指定了运行时版本,您可以在所选IDE的用户界面中轻松地对其进行编辑。如果您希望手动编辑项目文件,则只需编辑.csproj XML文件并更改TargetFramework元素的值即可。该值指的是识别版本的名字对象(如netcoreapp2.0)。

试试这个: 安装软件包Microsoft.EntityFrameworkCore.Tools

如果问题仍然存在,则执行以下操作:
更新包Microsoft.EntityFrameworkCore.Tools

按照本文档中的步骤帮助我解决了问题-

在Visual Studio中使用包管理器控制台构建数据库

  • 打开Visual Studio并为C#创建新的控制台应用程序(.NET Core)
  • 使用PackageManager控制台为EF Core添加MySQL NuGet包。例如,使用以下命令添加MySql.Data.EntityFrameworkCore v8.0.13包:
安装包MySql.Data.EntityFrameworkCore-版本8.0.13

重要

版本(例如,-8.0.13版)必须与您使用的实际连接器/网络版本匹配。获取当前版本信息

  • 通过选择其中一个软件包安装以下NuGet软件包 管理器控制台或管理工具中解决方案的NuGet包 然后是NuGet Package Manager菜单:

    Microsoft.EntityFrameworkCore.Design
    
    EF Core 1.1 only: Also add the MySql.Data.EntityFrameworkCore.Design package.
    
    Microsoft.EntityFrameworkCore.Tools version 1.1.6 (for EF Core 1.1) and Microsoft.EntityFrameworkCore.Tools version 2.0.3 (for EF Core 2.0)
    Note
    
    The .NET tools are included in the .NET Core 2.1 SDK and not required or supported for EF Core 2.1. If this is an upgrade, remove the reference to that package from the .csproj file (version 2.0.3 in this example) :
    
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.3" />
    
    Microsoft.EntityFrameworkCore.Design
    仅限EF Core 1.1:还添加MySql.Data.EntityFrameworkCore.Design包。
    Microsoft.EntityFrameworkCore.Tools版本1.1.6(适用于EF Core 1.1)和Microsoft.EntityFrameworkCore.Tools版本2.0.3(适用于EF Core 2.0)
    注
    .NET工具包含在.NET Core 2.1 SDK中,EF Core 2.1不需要或不支持这些工具。如果这是升级,请从.csproj文件(本例中为2.0.3版)中删除对该包的引用:
    
    打开Package Manager Console,并在提示下输入以下命令,为
    sakila
    数据库创建实体和
    DbContext
    (调整连接字符串值以匹配用户=和密码=选项的设置):

Scaffold DbContext“server=localhost;port=3306;user=root;password=mypass;database=sakila” MySql.Data.EntityFrameworkCore-OutputDir sakila-f

Visual Studio在项目内创建一个新的sakila文件夹,其中包含映射到实体的所有表和sakilaContext.cs文件


尽管Oracle说明说EF Core 2.1不需要Microsoft.EntityFrameworkCore.Tools,但我安装了与EF 2.2兼容的2.2.0版,对我有效的解决方案是在Package Manager控制台中运行以下命令:

PM> Install-Package Microsoft.EntityFrameworkCore -Version 2.1.11
PM> Install-Package Microsoft.EntityFrameworkCore.Tools -Version 2.1.11
确保版本与错误消息中的版本匹配在我的情况下,我遇到以下错误:

The EF Core tools version '2.1.1-rtm-30846' is older than that of the runtime '2.1.11-servicing-32099'. Update the tools for the latest features and bug fixes.
检查以下站点提供的版本:

对特定的版本使用命令行、Cmd或PowerShell:

dotnet工具更新--全局dotnet ef--版本3.1.0

或用于最新版本的使用(也适用于重新安装):

dotnet工具更新——像Martin一样的全局dotnet ef
对特定版本使用命令行、Cmd或PowerShell:

dotnet工具更新--全局dotnet ef--版本3.1.0

或用于最新版本(也适用于重新安装):

dotnet工具更新--全局dotnet ef

但是,我的电脑有问题: “在运行命令(不指定任何版本)时,我遇到以下错误:工具'dotnet ef'由于以下原因无法更新:
The EF Core tools version '2.1.1-rtm-30846' is older than that of the runtime '2.1.11-servicing-32099'. Update the tools for the latest features and bug fixes.
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.2">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>