dotnet ef command not working after VS for Mac update

4.6k views Asked by At

I've been using VS for Mac for a while now with EF Core 2.2 and everything's been going alright. Today I updated VS for Mac since it was really out of date, and after the update I can no longer run the dotnet ef command:

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.

Note that this is .NET Core 2.2 and EF Core 2.2, not 3.0. Everything I've read online is specific to 3.0, so could someone please instruct me on how to get this command to finally work? Here are some things I've already tried:

  • wiping the packages and re-installing them
  • running dotnet restore
  • explicitly adding the Microsoft.EntityFrameworkCore.Design package
  • explicitly adding the Microsoft.EntityFrameworkCore.Tools package
  • explicitly re-installing Microsoft.EntityFrameworkCore
  • rebooting VS for Mac
  • rebooting the Mac itself
4

There are 4 answers

1
Superman.Lopez On BEST ANSWER

For those that are having this issue after switching to zsh (for example after upgrading to macOS Catalina): the default path for globally installed tools is not recognised by zsh and now requires to reference the relevant path in your profile (.zshrc). This can be done by adding the following lines:

# Add .NET Core SDK global tools/packages
export PATH=$HOME/.dotnet/tools:$PATH"

See further background on why this was different from bash in: https://github.com/dotnet/cli/issues/9321

0
D-Rised On

Try this:

dotnet tool uninstall dotnet-ef -g
dotnet tool install dotnet-ef -a arm64 -g
0
riqitang On

Figured it out. When I updated VS for Mac it installed .NETCore SDK v3.0, so every time I ran the dotnet command it was using the version 3 executable. After removing that SDK version (by following these instructions https://learn.microsoft.com/en-us/dotnet/core/versions/remove-runtime-sdk-versions?tabs=macos#uninstalling-net-core), it’s now using the correct version for the project and the dotnet ef command is working again

1
Moshood Aminu On

Had same issue too, you don't have to uninstall v3.0. Eventually found out that the dotnet ef isn't longer part of the .netcore SDK.

You will need to install the ef tool for the specific version you want (In my case, 2.2). Run the command below on terminal:

dotnet tool install --global --version 2.2 dotnet-ef

Note that I specified global, you can as well specify local.

You should get an output with some information on how to add it to your profile and finally run:

zsh -l

and export to PATH:

export PATH="$PATH:/Users/username/.dotnet/tools"

For more information:

https://learn.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet

Breaking changes in dotnet-ef