C# Visual Studio EF 工具已过时 - 应使用 3.0.0 但仅使用 2.2.4

si2*_*030 1 c# entity-framework .net-core

我在 Powershell 中运行以下命令来创建初始迁移:

dotnet ef migrations add INITIAL --context CATALOGDbContext -s ../Jobsledger.API
Run Code Online (Sandbox Code Playgroud)

虽然它有效(我能够创建迁移和数据库),但它提供以下警告:

EF Core 工具版本“2.2.4-servicing-10062”早于运行时“3.0.0”。更新工具以获取最新功能和错误修复。

我认为这会导致结果出现问题,因为我的表现在缺少第一条记录中的 id。它的字面意思是空白。我不知道这如何在 2.2.4 中完美运行,但现在升级到 3.0.0,它创建了第一个带有空白 id 字段的记录......

我访问了站点“ Entity Framework Core 工具参考 - Visual Studio 中的包管理器控制台”,其中完成了升级工具的步骤。

虽然我已将所有内容都设置为 3.0.0,但即使我在此页面上尝试了他们的建议,我仍然收到上述错误。我确实更新了 .csproj 文件,我什至尝试了包管理器控制台选项,但仍然出现错误。

我使用的是完全升级到版本 16.4.0 Preview 1 的 Visual Studio 19。

如何让此警告消失,即如何更新 EF 工具?

更新 所以我从头开始重建我的项目,以确保我再次添加了所有包并且仍然得到相同的结果。

我还删除了 nuget 目录中的所有内容,并让它再次重新加载所有包,但仍然得到相同的结果。

这个项目由三个项目web项目和两个数据库类库组成。

这是我用于 Web 项目的 csproj 文件。

<PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
    <TypeScriptToolsVersion>3.6</TypeScriptToolsVersion>
    <TypeScriptBuildMode>true</TypeScriptBuildMode>
</PropertyGroup>

<ItemGroup>
  <Compile Remove="ControllerServices\Catalog\UserServices\UserValidateService.cs" />
  <Compile Remove="Controllers\SampleDataController.cs" />
  <Compile Remove="Controllers\SelectDataController.cs" />
</ItemGroup>

<ItemGroup>
  <Content Remove="wwwroot\favicon.ico" />
</ItemGroup>

<ItemGroup>
  <None Remove="ClientApp\app\components\clients\clientList\client-detail-view.ts" />
  <None Remove="ClientApp\app\components\clients\clientList\objectkeysValueConverter.ts" />
  <None Remove="ClientApp\app\navmenu\ActiveRoute.ts" />
</ItemGroup>


<ItemGroup>
    <PackageReference Include="FluentValidation" Version="8.5.0" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="5.5.0" />
    <PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.19" />
</ItemGroup>


<ItemGroup>
  <Folder Include="wwwroot\" />
</ItemGroup>


<ItemGroup>
  <ProjectReference Include="..\JobsLedger.CATALOG\JobsLedger.CATALOG.csproj" />
  <ProjectReference Include="..\JobsLedger.DATA\JobsLedger.DATA.csproj" />
</ItemGroup>


<ItemGroup>
  <TypeScriptCompile Include="ClientApp\app\components\clients\clientList\client-detail-view.ts" />
  <TypeScriptCompile Include="ClientApp\app\navmenu\activeRoute.ts" />
</ItemGroup>

<ItemGroup>
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0" />
</ItemGroup>

<Target Name="DebugRunWebpack" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('wwwroot\dist') ">
    <!-- Ensure Node.js is installed -->
    <Exec Command="node --version" ContinueOnError="true">
        <Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
    </Exec>
    <Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />

    <!-- In development, the dist files won't exist on the first run or when cloning to
             a different machine, so rebuild them if not already present. -->
    <Message Importance="high" Text="Performing first-run Webpack build..." />
    <Exec Command="npm install" />
    <Exec Command="npm ddp" />
    <Exec Command="npm run webpack:dev" />
</Target>

<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
    <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
    <Exec Command="npm install" />
    <Exec Command="npm ddp" />
    <Exec Command="npm run webpack:$(Configuration)" />

    <!-- Include the newly-built files in the publish output -->
    <ItemGroup>
        <!-- First, clean up previously generated content that may have been removed. -->
        <ContentWithTargetPath Remove="@(ContentWithTargetPath)" Condition="!Exists('%(Identity)')" />
        <_WebpackFiles Include="wwwroot\dist\**" />
        <ContentWithTargetPath Include="@(_WebpackFiles->'%(FullPath)')" RelativePath="%(_WebpackFiles.Identity)" TargetPath="%(_WebpackFiles.Identity)" CopyToPublishDirectory="Always" />
    </ItemGroup>
</Target>
Run Code Online (Sandbox Code Playgroud)

这是 CATALOG 数据库类库的 csproj 文件。

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

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

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.19" />
  </ItemGroup>

  <ItemGroup>
    <Reference Include="Microsoft.AspNetCore.Http.Abstractions">
      <HintPath>..\..\..\Program Files\dotnet\packs\Microsoft.AspNetCore.App.Ref\3.0.0-preview5-19227-01\ref\netcoreapp3.0\Microsoft.AspNetCore.Http.Abstractions.dll</HintPath>
    </Reference>
  </ItemGroup>

</Project>
Run Code Online (Sandbox Code Playgroud)

这是最后一个类库DATA的csproj文件

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

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

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.19" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\JobsLedger.CATALOG\JobsLedger.CATALOG.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Reference Include="Microsoft.AspNetCore.Http.Abstractions">
      <HintPath>..\..\..\Program Files\dotnet\packs\Microsoft.AspNetCore.App.Ref\3.0.0-preview5-19227-01\ref\netcoreapp3.0\Microsoft.AspNetCore.Http.Abstractions.dll</HintPath>
    </Reference>
  </ItemGroup>

</Project>
Run Code Online (Sandbox Code Playgroud)

我如何让这个项目使用 EntityFramework 工具 3.0.0??

小智 5

本周我遇到了类似的问题,对我有用的是卸载实体框架工具并重新安装它们。

  1. 卸载: dotnet tool uninstall --global dotnet-ef
  2. 再次安装: dotnet tool install --global dotnet-ef --version 3.0.0-*

对我来说,--version成功了,否则我会遇到有线错误。