Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command dotnet ef not found

I'm following the docs in order to create an initial migration. When I execute dotnet, I get the help section, meaning that the PATH works properly.

Then I try to execute the command below from the docs in console window:

dotnet ef migrations add InitialCreate

I get the following error:

Could not execute because the specified command or file was not found.
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.

  • You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

  • I excluded the first item since I copied the command.

  • I excluded the second item because the package Microsoft.EntityFrameworkCore.SqlServer is installed.

  • I excluded the third item because I get the help section when invoking dotnet.

I'm googling the issue but since the version is new, there's not much to go on and/or it's drowning in similar issues from earlier versions.

I tried to forcibly install Microsoft.EntityFrameworkCore just in case it needs to be explicitly added. I ran into the error message telling me that the latest version to pick from is 2.2.6 and a downgrade is a no-go. I'm not sure how to install the version compatible with the SQL-package I have on my system already (and even less certain if that's right approach to kill this issue).

Detected package downgrade: Microsoft.EntityFrameworkCore from 3.0.0-preview6.19304.10 to 2.2.6. Reference the package directly from the project to select a different version.
Web ->
Microsoft.EntityFrameworkCore.SqlServer 3.0.0-preview6.19304.10 ->
Microsoft.EntityFrameworkCore.Relational 3.0.0-preview6.19304.10 ->
Microsoft.EntityFrameworkCore (>= 3.0.0-preview6.19304.10)
Web -> Microsoft.EntityFrameworkCore (>= 2.2.6)

like image 994
Konrad Viltersten Avatar asked Jul 16 '19 23:07

Konrad Viltersten


People also ask

Why dotnet EF is not recognized?

Possible reasons for this include: * You misspelled a built-in dotnet command. * You intended to execute a . NET program, but dotnet-xyz does not exist. * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

What is dotnet EF?

dotnet ef dbcontext scaffold. Generates code for a DbContext and entity types for a database. In order for this command to generate an entity type, the database table must have a primary key.

Could not execute because the specified command or file was not found Possible reasons for this include?

Could not execute because the specified command or file was not found. Possible reasons for this include: * You misspelled a built-in dotnet command. * You intended to execute a . NET program, but dotnet-ef does not exist.


2 Answers

See the announcement for ASP.NET Core 3 Preview 4, which explains that this tool is no longer built-in and requires an explicit install:

The dotnet ef tool is no longer part of the .NET Core SDK

This change allows us to ship dotnet ef as a regular .NET CLI tool that can be installed as either a global or local tool. For example, to be able to manage migrations or scaffold a DbContext, install dotnet ef as a global tool typing the following command:

dotnet tool install --global dotnet-ef 

To install a specific version of the tool (see all available versions at nuget.org), use the following command:

dotnet tool install --global dotnet-ef --version 3.1.4 

The reason for the change is explained in the docs:

Why

This change allows us to distribute and update dotnet ef as a regular .NET CLI tool on NuGet, consistent with the fact that the EF Core 3.0 is also always distributed as a NuGet package.

In addition, you might need to add the following NuGet packages to your project:

  • Microsoft.EntityFrameworkCore.SqlServer
  • Microsoft.EntityFrameworkCore.Design
  • Microsoft.EntityFrameworkCore.Tools
like image 166
Kirk Larkin Avatar answered Sep 23 '22 19:09

Kirk Larkin


If you are using a Dockerfile for deployments these are the steps you need to take to resolve this issue.

Change your Dockerfile to include the following:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env ENV PATH $PATH:/root/.dotnet/tools RUN dotnet tool install -g dotnet-ef --version 3.1.1 

Also change your dotnet ef commands to be dotnet-ef

like image 29
Nick Spicer Avatar answered Sep 24 '22 19:09

Nick Spicer