当我在VS 2017包管理器控制台中使用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>

我已经确认安装的版本实际上已经过时了:

PM> dotnet ef --version
Entity Framework Core .NET Command-line Tools
2.1.1-rtm-30846

那么我该怎么更新工具呢?顺便说一句,我在其他答案中看到过一个过时的全局。Json文件会导致这个问题。但是我没有全局。Json文件在解决方案的任何地方。


当前回答

我在github上把这个问题转给了开发团队。事实证明,这是一个已知的问题,在当前的工具或nuget包中,当你创建一个EF Core驱动的AspNet Core站点时加载。这个问题将在未来的版本中修复。

目前,解决方法是忽略该警告。

还提供了另一种解决方案,包括调整csproj文件来明确定义AspNet核心元包的版本——当我写这篇文章时,它已经达到2.1.3了——但我无法让这种方法工作;我还是不断收到警告信息。

其他回答

要解决这个问题,你可以采用以下技巧之一:


技术1:使用包管理器控制台(特别是Microsoft Visual Studio用户)PM>安装-Package Microsoft. entityframeworkcore . tools -Version 2.1.2 技术二:使用。net CLI > dotnet添加包Microsoft.EntityFrameworkCore.Tools—version 2.1.2 技术3:使用包引用

<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.2">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

技术四:使用Packet CLI >包添加Microsoft.EntityFrameworkCore.Tools—version 2.1.2

记住:要使用这个版本,你需要NuGet 3.6或更高版本。 参考链接:https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Tools/2.1.2

通过dotnet CLI或Package Manager Console或访问更新EF Core工具 这个网站https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Tools/2.1.2 或者你可以忽略这一点。这不是什么大问题……

我的解决方案是从微软https://www.nuget.org/packages/dotnet-ef安装工具dotnet-ef。它使用相同的命令,但没有警告。变化是使用dotnet-ef而不是dotnet ef。

如果你已经安装了。net-ef,那么使用 Dotnet工具更新——global Dotnet -ef——version N.N.N (N.N.N您要更新到的版本)

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

遵循本文档中的步骤帮助我解决了问题- https://docs.oracle.com/cd/E17952_01/connector-net-en/connector-net-entityframework-core-scaffold-example.html

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

打开Visual Studio并创建一个新的控制台应用程序(。NET Core)。 使用包管理器控制台为EF Core添加MySQL NuGet包。例如,使用以下命令添加MySql.Data.EntityFrameworkCore v8.0.13包:

安装MySql.Data.EntityFrameworkCore -Version 8.0.13

重要的

版本(例如,-Version 8.0.13)必须与您正在使用的实际Connector/NET版本匹配。查看当前版本信息。

Install the following NuGet packages by selecting either Package Manager Console or Manage NuGet Packages for Solution from the Tools and then NuGet Package Manager menu: 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" /> Open Package Manager Console and enter the following command at the prompt to create the entities and DbContext for the sakila database (adjust the connection-string values to match your settings for the user= and password= options):

Scaffold-DbContext”= localhost服务器端口= 3306;= root用户数据库密码= mypass; = sakila” MySql数据。EntityFrameworkCore -OutputDir sakila -f

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

尽管Oracle指示说EF Core 2.1不需要Microsoft.EntityFrameworkCore.Tools,但我还是安装了与EF 2.2兼容的2.2.0版本