当我在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文件在解决方案的任何地方。
对我有效的解决方案是在包管理器控制台中运行以下命令:
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.
查看以下站点的可用版本:
https://www.nuget.org/packages/Microsoft.EntityFrameworkCore/
遵循本文档中的步骤帮助我解决了问题- 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版本
忽略这个问题
不要更新你的< PackageReference Include = "微软。EntityFrameworkCore。Tools " Version ="" / > .
在我的情况下,我向前移动与'Update-Database -Context MyElementContext',现在它都工作得很好。
我是在《编程ASP》这本书里找到的。迪诺·埃斯波西托的NET Core。
'Note This version of the CLI tooling is not the same as the version of the .NET Core runtime the application will use. The runtime version is specified in the project file, and you can comfortably edit it from within the user interface of the IDE of your choice. If you want, instead, to edit the project file manually, then it is as easy as editing the .csproj XML fi le and changing the value of the TargetFramework element. The value refers to the moniker that identifies the version (such as netcoreapp2.0).'