Cannot find command 'dotnet ef'?

血红的双手。 提交于 2019-12-03 09:52:28

How to fix this

For Linux and macOS, add a line to your shell's configuration:

  • bash/zsh:

    export PATH="$PATH:$HOME/.dotnet/tools/"
    
  • csh/tcsh:

    set path = ($path $HOME/.dotnet/tools/)
    

When you start a new shell/terminal (or the next time you log in) dotnet ef should work.

For Windows:

See this question on how to add to the PATH environment variable.

You need to add %USERPROFILE%\.dotnet\tools to the PATH.

What's going on?

The .NET Core 3.0 (preview) version of this failure is much more illuminating:

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

The second and the third one both refer to dotnet trying to find a dotnet-ef command but can't find it. As the third point says, dotnet-ef is not in your path.

Here's what the docs say:

Global Tools can be installed in the default directory or in a specific location. The default directories are:

OS Path

Linux/macOS $HOME/.dotnet/tools

Windows %USERPROFILE%\.dotnet\tools

So, you should add $HOME/.dotnet/tools/ to your $PATH.

But also note this part from docs:

These locations are added to the user's path when the SDK is first run, so Global Tools installed there can be called directly.

So, it sounds like something went wrong. If you installed using a manual tarball, the SDK screwed up and you should report this bug to Microsoft. If you use a distribution package, they screwed up and you should report this as a bug to them.

In my case, the tools folder didn't exist inside %USERPROFILE%\.dotnet\ so I had to run the command dotnet tool install --global dotnet-ef to install dotnet ef. Then I was able to run dotnet ef...

This was the result of the above install command:

baruchiro

Sometimes when you install a new version of dotnet sdk, it hits the PATH.

You have to manually add the folder .dotnet/tools from your home directory to PATH.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!