547

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)

0

18 Answers 18

1060

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

.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.

4
  • 16
    After installing the tool... same error. When try to re-install Tool 'dotnet-ef' is already installed.. Yet running dotnet ef results in the error in the OP Commented Feb 1, 2023 at 3:54
  • 3
    @DouglasGaskell That usually means it's a path issue: stackoverflow.com/a/60938208/2630078. Commented Feb 5, 2023 at 18:28
  • 1
    To keep this answer valid for future, i think we should modify the answer for .net 8 to: dotnet tool install --global dotnet-ef --version 8.*
    – Ateik
    Commented Dec 5, 2023 at 6:28
  • I had to make sure the tool matched my exact EF version, and to do that I used update in place of install
    – Savage
    Commented Jun 13 at 14:11
39

I solved this problem by installing dotnet-f tool locally with the following commands.

If you are setting up this repository

dotnet new tool-manifest

dotnet tool install --local dotnet-ef --version 5.0.6

Then use dotnet dotnet-ef instead of dotnet-ef.

4
  • 1
    Please note that the question is a bit dated and at the time of it's creation, the considered version was .NET Core 3.x whereas your solution suggests .NET Core 5 (or rather .NET 5 or whatever MS calls it this week). I still appreciate your answer (hence the upvote) and I'd like it to stay. Just making a remark for the future, sloppy reader. Commented Jun 8, 2021 at 14:53
  • I am using .net 7 and this worked the other way for .net 7 did not and that is on their documentations
    – AlThePal78
    Commented May 16, 2023 at 2:54
  • I'm using mac and thats worked me.
    – Fatih
    Commented Jul 27, 2023 at 14:41
  • I'm using github codespace and that's worked me . Commented Nov 7, 2023 at 6:44
38

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

1
  • 2
    In case still, the PATH doesn't work, use ENV directive like this: ENV PATH $PATH:/root/.dotnet/tools Commented Mar 18, 2020 at 8:59
19

Global tools can be installed in the default directory or in a specific location. The default directories are:

  • Linux/macOS ---> $HOME/.dotnet/tools

  • Windows ---> %USERPROFILE%\.dotnet\tools

If you're trying to run a global tool, check that the PATH environment variable on your machine contains the path where you installed the global tool and that the executable is in that path.

Troubleshoot .NET Core tool usage issues

3
  • 1
    This was my problem, when I installed on MacOS via "dotnet tool install --global dotnet-ef" I got a prompt to close and reopen the terminal window so that the new configuration would take effect, but in fact the default installation folder $HOME/.net/tools had not been added to the PATH variable. Commented Apr 22, 2020 at 13:32
  • I am glad it helped you :)
    – Gambitier
    Commented Apr 22, 2020 at 13:51
  • 1
    Why does a global install put things in $HOME? And why doesn't it tell you that you need to augment you PATH? It's barmy... Commented Jul 29, 2022 at 0:27
13

For everyone using .NET Core CLI on MinGW MSYS:

After installing using

dotnet tool install --global dotnet-ef

add this line to to the bashrc file (C:\msys64\home\username\ - .bashrc (the location depends on your setup)

export PATH=$PATH:/c/Users/username/.dotnet/tools
3
  • This answer does not tackle the problem the OP has. Please consider answering the general question, while also introducing this specific way of solving the issue.
    – lnjuanj
    Commented Oct 22, 2020 at 10:05
  • OP does not explain its environment. A "console window" could use many environment.
    – thebennies
    Commented Oct 27, 2020 at 1:59
  • This works for Ubuntu as well. I'm surprised this is not documented anywhere
    – jack4it
    Commented Dec 21, 2020 at 20:10
10

This will work for me on Visual studio code, in Ubuntu

dotnet tool install --global dotnet-ef
dotnet tool restore

After that all the execution are done like

dotnet tool run dotnet-ef

or

dotnet dotnet-ef
1
  • 4
    Firstly You should create manifest : dotnet new tool-manifest and then dotnet tool install --local dotnet-ef
    – ParisaN
    Commented Dec 6, 2022 at 21:09
8

Run PowerShell or a command prompt as administrator and run the below command.

dotnet tool install --global dotnet-ef --version 3.1.3
5

If you're using Snap package dotnet-sdk on Linux, this can be resolved by updating your ~.bashrc file / etc. as follows:

#!/bin/bash
export DOTNET_ROOT=/snap/dotnet-sdk/current
export MSBuildSDKsPath=$DOTNET_ROOT/sdk/$(${DOTNET_ROOT}/dotnet --version)/Sdks
export PATH="${PATH}:${DOTNET_ROOT}"
export PATH="$PATH:$HOME/.dotnet/tools"
1
  • 1
    What do you mean by "/ etc"? et cetera? Or the directory / etc? Or something else? In any case, can you elaborate? Commented Jun 10, 2021 at 14:16
5

Sometimes it may occur due to different users within a system.

So to resolve the problem, you can install the dotnet-ef locally in your solution rather than adding it globally.

Steps to install locally.

  1. Create a local manifest file via dotnet new tool-manifest

  2. Go to the config folder:

    cd .\.config

  3. Install the tool via dotnet tool install dotnet-ef --version versionNumber. It'll be successfully installed and its commands will be accessible within the project.

2
  • 3
    I suggest that you check the existing answers before posting an own. The issue is due to an early stage of the version (check the date of the post). Commented May 21, 2021 at 13:23
  • 1
    thanks for the information, but this problem occurred recently with me using .net 5 and this was the only solution I found, so it may help someone. Commented May 25, 2021 at 7:44
5

I had same problem on ubuntu.

First install dotnet-ef

dotnet tool install --global dotnet-ef --version 6.0.0

Then you need to add path to bashrc.

Open bashrc:

vim ~/.bashrc

Add following:

export PATH="$PATH:$HOME/.dotnet/tools/"

Then execute this:

source ~/.bashrc
4

The reason is - The dotnet ef tool is no longer part of the .NET Core SDK in ASP.NET Core 3.0.

Solution: Install dotnet ef as a global tool

Steps:

  1. Run PowerShell or command prompt as Administrator in the project root
  2. Run below command.

For the latest version:

dotnet tool install --global dotnet-ef

For a specific version:

dotnet tool install --global dotnet-ef --version <<version_number>>

2

I was having this problem after I installed the dotnet-ef tool using Ansible with sudo escalated privilege on Ubuntu. I had to add become: no for the Playbook task, and then the dotnet-ef tool became available to the current user.

  - name: install dotnet tool dotnet-ef
    command: dotnet tool install --global dotnet-ef --version {{dotnetef_version}}
    become: no
1
  • Where should it go? For example, a file? What is the name of the file? Or something else? Commented Jun 10, 2021 at 14:32
1

If you ask yourself what versions are available:

Versions tab on this page: https://www.nuget.org/packages/dotnet-ef/

Besides that as others already mentioned it's:

dotnet tool install --global dotnet-ef --version 5.0.11
0

I had the same problem. I resolved it by uninstalling all the versions on my PC and then reinstalling dotnet.

1
  • 8
    Better suited as a comment. Should explain how to resolve and why with resources
    – Josh Adams
    Commented Feb 25, 2020 at 15:56
0

I followed these steps, and it worked fine for me:

  1. Add a source:

    dotnet nuget add source --name nuget.org https://api.nuget.org/v3/index.json
    
  2. Run the installation command line:

    dotnet tool install --global dotnet-ef --version 5.0.6
    
0

In my case, I received a 401 Unauthorized when trying to install dotnet ef.

In the end, I found another link Telerik resolution that helped.

Summed up, using Visual Studio 2022, the steps needed was:

  1. remove the Telerik source from Tools > Nuget Package Manager > Package Source
  2. run this command to add the source and force it to use provided credentials:

dotnet nuget add source "https://nuget.telerik.com/v3/index.json" -u "username" -p "password" -store-password-in-clear-text

Then I could continue to follow Kirk's steps and install dotnet ef

Note: Not ideal to use -store-password-in-clear-text, but there was another issue with encrypted credentials. So for now just used that

3
  • I can't imagine how that's relevant approach to resolving that error. Telerik is a 3rd party supplier for some component for GUIs, aren't they? Commented Oct 28, 2023 at 11:09
  • Well, I'm not sure what went wrong. One of the other messages I received when trying to install EF was: Failed to retrieve information about 'donet-ef' from remote source 'nuget.telerik.com/v3/package/dotnet-ef/index.json' So there was definately an issue with the Nuget sources (brand new install on a new laptop...thus the need to reinstall EF) I tried various other solutions, but the only one that worked was the Telerik resolution linked in my first post.
    – Kemono
    Commented Oct 30, 2023 at 8:25
  • Exciting... It seem, though, that there's something with the NuGet repositories on your local environment. I haven't ever-ever got anything with Telerik during so many years, so I'm pretty certain it's unrelated in a general sense. Commented Oct 31, 2023 at 16:26
0

I had the same issue, just add this to your PATH: %USERPROFILE%.dotnet\tools

0

I searched for hours, but nothing seemed to work above. I had one project that was working and saw that in the project where this was not working, I was missing a file like so ~/config/dotnet-tools.json with the following:

{ "version": 1, "isRoot": true, "tools": { "dotnet-ef": { "version": "8.0.4", "commands": [ "dotnet-ef" ] } } }

Not the answer you're looking for? Browse other questions tagged or ask your own question.