'.NET EF in Dotnet 6 installed, but when calling it it tells me command or file was not found

I did install dotnet ef using this command

dotnet tool install --global dotnet-ef

It returned

Tool 'dotnet-ef' is already installed.

I assume that it is correctly installed.

When running the command below inside my project

dotnet ef migrations add InitialMigration

it returns

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.
  * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

Dotnet SDK version: 6.0.101 Device: Macbook Air M1

NB: I tried using the x64 version of dotnet via Rosetta. No luck, the same issue persists.

How to fix it?



Solution 1:[1]

I had the same problem You can try installing ef tool locally Go to your source directory then:

dotnet new tool-manifest
dotnet tool install  dotnet-ef

Solution 2:[2]

The version 6 of this tool doesn't work for some reason.

dotnet tool uninstall --global dotnet-ef
dotnet tool install --global dotnet-ef --version 5
cat << \EOF >> ~/.zprofile
# Add .NET Core SDK tools
export PATH="$PATH:/Users/jp/.dotnet/tools"
EOF
zsh -l
nano .zshrc

then add to the start of the file this /Users/jp/.dotnet/tools. It should look something like this

export PATH=/Users/yourusername/.dotnet/tools:/opt/homebrew/bin:...

Then

dotnet tool update --global dotnet-ef

Solution 3:[3]

I had the very same issue on Windows 10. Even if dotnet-ef was installed successfully in global environment, it was not found even if my user specific path indeed contained %USERPROFILE%\.dotnet\tools.

Other things related to VS Code lieke code -r <projectpath> were also not working properly.

I realized, my user specific path variable was not merged with system path. Perhaps my system path was too long (about 4200 characters)?

So my solution was to significantly shorten the system path by removing entries not longer required.

A second step was to use regedit to convert system path from "REG_SZ" type into "REG_EXPAND_SZ" type and substitute long and repeated parts.

Well, it works for me perfectly.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Reza Ariyan
Solution 2 Jean-Paul Abi-Ghosn
Solution 3 Merilix2