Command dotnet ef not found
C#asp.net Core.Net CoreEntity Framework-Core.Net Core-3.0C# Problem Overview
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)
C# Solutions
Solution 1 - C#
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:
Solution 2 - C#
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
Solution 3 - C#
> 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.
Solution 4 - C#
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.
Solution 5 - C#
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
Solution 6 - C#
Run PowerShell or a command prompt as administrator and run the below command.
dotnet tool install --global dotnet-ef --version 3.1.3
Solution 7 - C#
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
Solution 8 - C#
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
Solution 9 - C#
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:
- Run PowerShell or command prompt as Administrator in the project root
- 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>>
Solution 10 - C#
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"
Solution 11 - C#
I had the same problem. I resolved it by uninstalling all the versions on my PC and then reinstalling dotnet
.
Solution 12 - C#
I followed these steps, and it worked fine for me:
-
Add a source:
dotnet nuget add source --name nuget.org https://api.nuget.org/v3/index.json
-
Run the installation command line:
dotnet tool install --global dotnet-ef --version 5.0.6
Solution 13 - C#
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.
-
Create a local manifest file via
dotnet new tool-manifest
-
Go to the
config
folder:cd .\.config
-
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.
Solution 14 - C#
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
Solution 15 - C#
you can run this command
dotnet tool install dotnet-ef -g
then every things will works good :)