Search code examples
c#asp.net-core.net-coreentity-framework-core.net-core-3.0

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)


Solution

  • To install the dotnet-ef tool, run the following command:

    .NET 9

    dotnet tool install --global dotnet-ef --version 9.*
    

    .NET 8

    dotnet tool install --global dotnet-ef --version 8.*
    

    .NET 7

    dotnet tool install --global dotnet-ef --version 7.*
    

    .NET 6

    dotnet tool install --global dotnet-ef --version 6.*
    

    .NET 5

    dotnet tool install --global dotnet-ef --version 5.*
    

    .NET Core 3

    dotnet tool install --global dotnet-ef --version 3.*
    

    For more information about the history of dotnet-ef, see the announcement for ASP.NET Core 3 Preview 4, which explains that this tool was changed from being built-in to requiring 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.