efcore icon indicating copy to clipboard operation
efcore copied to clipboard

dotnet ef Could not execute because the specified command or file was not found

Open senthilsivaraman opened this issue 6 years ago • 17 comments

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 image

image

I found it is working when i check in systems cmd

4

senthilsivaraman avatar Feb 02 '20 00:02 senthilsivaraman

Could be related to #19722. The interesting thing here is that dotnet thinks the command is installed but then can't find it:

image

@wli3 @bricelam Thoughts?

ajcvickers avatar Feb 03 '20 21:02 ajcvickers

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

wli3 avatar Feb 04 '20 05:02 wli3

It was working well before. I restored my olc github code of the project, after that it started behave like this

senthilsivaraman avatar Feb 04 '20 06:02 senthilsivaraman

WLi. sorry I don't understand what you are telling me to do.

In my understanding, echo is like console.writeLine

senthilsivaraman avatar Feb 04 '20 17:02 senthilsivaraman

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.

wli3 avatar Feb 05 '20 05:02 wli3

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

senthilsivaraman avatar Feb 05 '20 16:02 senthilsivaraman

Check you screenshot again. Your seems using powershell in vscode. So the command should be echo $env:path. Also, are you using WSL?

wli3 avatar Feb 05 '20 23:02 wli3

today even in my system cmd it is not working Capture

Capture

senthilsivaraman avatar Feb 05 '20 23:02 senthilsivaraman

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?

wli3 avatar Feb 06 '20 00:02 wli3

11

These are my system variables path

senthilsivaraman avatar Feb 06 '20 00:02 senthilsivaraman

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.

wli3 avatar Feb 06 '20 00:02 wli3

So what should I do Li.

senthilsivaraman avatar Feb 06 '20 00:02 senthilsivaraman

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

ajcvickers avatar Feb 07 '20 23:02 ajcvickers

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

wowfood avatar Apr 22 '20 21:04 wowfood

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.

j-nord avatar May 29 '20 10:05 j-nord

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

Maikon014 avatar Jan 29 '21 01:01 Maikon014

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.

adinastan avatar Apr 19 '21 11:04 adinastan