dotnet ef Could not execute because the specified command or file was not found
In angular + asp.net core 3.1 project, I am getting this error, whenever I try to access anything related to EF.
dotnet ef 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
Everything was working fine before. Due to some error I downloaded my old package of the project from GitHub and pasted, and now getting this error.
I have already set environment variables too
https://i.stack.imgur.com/wgoMB.jpg


I found it is working when i check in systems cmd
Could be related to #19722. The interesting thing here is that dotnet thinks the command is installed but then can't find it:

@wli3 @bricelam Thoughts?
I don't think it is related to #19722. This time, it is installed successfully, dotnet-ef.exe cannot be found on the PATH. You can access it in CMD means it is on system path. Maybe the vscode shell is not a normal cmd. You could try to run echo %PATH% in vscode shell and see if %userprofile%\.dotnet\tools is in it
It was working well before. I restored my olc github code of the project, after that it started behave like this
WLi. sorry I don't understand what you are telling me to do.
In my understanding, echo is like console.writeLine
run echo %PATH% in the vscode shell.
This will print out the PATH environmental variable. %userprofile%\.dotnet\tools or expended string should be part of the PATH value. If not, you need to configure it.
for me running run echo %PATH%
gives the output --> %PATH%
but if you find my 1st attached screenshot I have already added the path variable
Check you screenshot again. Your seems using powershell in vscode. So the command should be echo $env:path. Also, are you using WSL?
today even in my system cmd it is not working
Do you have special shell configuration? Is there other scripts overriding PATH?
Could you double check your "environment variable editor"? Is %userprofile%\.dotnet\tools still there? Could you also try to add C:\Users\Senthilkumar\.dotnet\tools directly?
These are my system variables path
At this point, this is beyond my expertise. Apparently a change in "environment variable editor" could not actually be reflected in environment variable of your shell. I highly suspect there is some a script overriding the environment variables after the shell runs.
So what should I do Li.
@senthilsivaraman If I were you at this point I would probably wipe your machine and reinstall. I know that's drastic, but unless we can reproduce what you are seeing it's very unlikely we will be able to help more. I suspect something has been corrupted at some point in the past.
I've just run into the exact same issue.
ran dotnet tool install --global ef
CMD line says it installed fine
Run dotnet ef, get the "Could not execute because the specified command could not be found" error.
Running dotnet tool uninstall --global ef finds it perfectly fine though.
To fix the issue I had to do the following.
Go to C:\Users\xxxxx.dotnet\tools.store
manually delete the ef folder. Then open a command prompt as administrator, and install the package through that, rather than through a command prompt from visual studios "open developer command prompt" option
I don't know if it's the "delete the folder" step, or the use elevated command prompt step that fixed it for me, but figured it's worth sharing, and this is the top thing that popped up in a google search
We have the same trouble. Every year and after every update the dotnet tools doesn't work correct. So we must spend hours to find errors because the tools have bugs over bugs.
I had the same issue on Ubuntu 20.04.1 with the .net Core 5.0.0-rc.1 and the solution that worked for me was to install the dotnet ef as a local tool.
SOLUTION
dotnet new tool-manifest dotnet tool install dotnet-ef --version 5.0.0-rc.1.20451.13 ( NOTE: you install according to your dotnet version).
I installed dotnet-ef globally in VS Package Manager Console:
dotnet tool install --global dotnet-ef
I added %USERPROFILE%\.dotnet\tools to the PATH environment variable.
In my case everything worked fine after I closed VS and reopened it again.