Home > Blockchain >  Cannot find command 'dotnet ef' (Powershell Core - LInux)
Cannot find command 'dotnet ef' (Powershell Core - LInux)

Time:04-02

I know there are plenty of answers regarding Dotnet-EF when utilizing the traditional Linux shells, but when using PowerShell Core to invoke the .NET global tools, the search engines just run me in circles. Searches of how to deal with Global tools using PowerShell always returns articles talking about installing PowerShell itself as a Global tool, which isn't the end goal.

I did searches for modifying path variables via $Profile, but when entering the following:

$env:PATH=$HOME/.dotnet/tools

I'd end up breaking PowerShell completely, i.e. Can't run anything; Linux CLI programs or PowerShell commands. So, I'd end up having to use a GUI text editor to remove the environment variable and start over. Even using a separate envVar.ps1 broke my terminal.

First Error:

PS /home/test> 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 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.

Second Error:

PS /home/> $env:PATH='$HOME/.dotnet/tools'
PS /home/> nvim
nvim: The term 'nvim' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
PS /home>

(Neovim is installed and worked fine prior to error and after variable was removed.)

Append - Dotnet-ef is installed:

PS /home> get-childitem .dotnet/tools

Directory: /home/.dotnet/tools

UnixMode   User             Group                 LastWriteTime           Size Name
--------   ----             -----                 -------------           ---- ----
-rwxr-xr-x user             user                3/29/2022 20:08         142840 dotnet-ef


PS /home/test> dotnet tool list -g
Package Id      Version      Commands
--------------------------------------
dotnet-ef       6.0.3        dotnet-ef

ANSWER:

PS /home/> $env:PATH = $env:PATH   ‘:’   ‘$HOME/.dotnet/tools'

CodePudding user response:

You probably need to install the ef tool per https://docs.microsoft.com/en-us/ef/core/get-started/overview/install#get-the-net-core-cli-tools - try dotnet tool list and if you can’t see it in the output then run this:

dotnet tool install --global dotnet-ef

And re the PATH environment variable, you’re overwriting the value rather than appending your extra folder name, which is why the operating system can’t find other applications afterwards.

You probably intended something like

PS /home/> $env:PATH = $env:PATH   ‘;’   ‘$HOME/.dotnet/tools'
  • Related