Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF Core Tools not working on dotnet core 3 preview 4

I am trying to develop some web APIs using dotnet core 3 preview 4. I am familiar to dotnet core and its libraries like EF core and Identity and etc. But now with the version 3 preview 4, Microsoft.EntityFrameworkCore.Tools does not work and the command dotnet ef migrations add ... tells this message:

Cannot find command 'dotnet ef', please run the following command to install

dotnet tool install --global dotnet-ef

the csproj file is like this:

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

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

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0-preview4-19216-03" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0-preview4.19216.3" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.0.0-preview4.19216.3" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0-preview4.19216.3"/>
  </ItemGroup>

</Project>

and also I have tried dotnet tool install --global dotnet-ef but not solved my issue. As the version 3 preview 4 is newly announced, I can't find any documentation about this on official or third-part sites.

like image 249
ConductedClever Avatar asked May 03 '19 17:05

ConductedClever


People also ask

Can Core 3.1 Use EF Core 5?

EF Core 5.0 requires a . NET Standard 2.1 platform. This means EF Core 5.0 will run on . NET Core 3.1 or .

Why dotnet EF is not recognized?

Possible reasons for this include: You misspelled a built-in dotnet command. You intended to execute a . NET Core program, but dotnet-ef does not exist.

How do I update EF core tools?

Update the tools Use dotnet tool update --global dotnet-ef to update the global tools to the latest available version. If you have the tools installed locally in your project use dotnet tool update dotnet-ef . Install a specific version by appending --version <VERSION> to your command.


Video Answer


2 Answers

.NET Core 3.0 introduces Local Tools:

Local tools are similar to global tools but are associated with a particular location on disk. Local tools aren't available globally and are distributed as NuGet packages.

dotnet Core and, also, EF Core, are evolving fast. It's easy to have several projects/solutions at different dotnet versions. With Local Tools you can configure specific version tools by project.

Steps to configure tool by project:

dotnet new tool-manifest  
#executing this at sln level (or with your projecte) a new .config file is created

#check lasts versions at:
#https://www.nuget.org/packages/dotnet-ef/

dotnet tool install --local dotnet-ef --version 3.1.4
#this will configure dotnet ef tool

dotnet ef
#should run at this point

At this point your ef migrations/database command must runs.

When people clone your repo should run:

dotnet tool restore
like image 76
dani herrera Avatar answered Oct 15 '22 14:10

dani herrera


Edit:

At this point dotnet core 3 is no longer preview, so select our version accordingly. (Check version)


First make sure that,

  1. You're using the .NET Core SDK 3.0 Preview, type dotnet --info and see there's a line like,
.NET Core SDKs installed:
  3.0.100-preview4-011223 [C:\Program Files\dotnet\sdk]
  1. You ran dotnet restore on the project
  2. You are cded to the project's (*.csproj) directory

With Entity Framework Core 3.0 Preview 4, dotnet-ef tool is no longer part of the .NET Core SDK. Uninstall the stable version of dotnet-ef tool (2.2.4 at this point) using,

dotnet tool uninstall --global dotnet-ef

Then install the preview or latest stable, (Check version)

dotnet tool install --global dotnet-ef --version 3.0.0-preview4.19216.3

After that dotnet ef should work fine.

like image 43
Nishan Avatar answered Oct 15 '22 16:10

Nishan