I am using .NET core 2.0 on Arch VScode and trying to get EF tools to work but I keep getting that error 'cannot find command dotnet ef'. I've just about looked everywhere and none of the suggestions worked. So if you can please help that would be much appreciated.
The result of running 'dotnet ef'
[wasiim@wasiim-PC WebApiServerApp]$ dotnet ef --help
Cannot find command 'dotnet ef', please run the following command to install
dotnet tool install --global dotnet-ef
[wasiim@wasiim-PC WebApiServerApp]$ dotnet tool list -g
Package Id Version Commands
---------------------------------------------------
dotnet-dev-certs 2.2.0 dotnet-dev-certs
dotnet-ef 2.2.3 dotnet-ef
[wasiim@wasiim-PC WebApiServerApp]$
this is the dotnet --info result, if it's of help
[wasiim@wasiim-PC WebApiServerApp]$ dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 2.2.105
Commit: 7cecb35b92
Runtime Environment:
OS Name: arch
OS Version:
OS Platform: Linux
RID: arch-x64
Base Path: /opt/dotnet/sdk/2.2.105/
Host (useful for support):
Version: 2.2.3
Commit: 6b8ad509b6
.NET Core SDKs installed:
2.2.105 [/opt/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.NETCore.App 2.2.3 [/opt/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
This is my .csproj file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Lucene.Net.Analysis.Common" Version="4.8.0-beta00005" />
<PackageReference Include="Lucene.Net.QueryParser" Version="4.8.0-beta00005" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.5" />
<PackageReference Include="Lucene.Net" Version="4.8.0-beta00005" />
<PackageGroup Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.4" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.3" />
</ItemGroup>
</Project>
Sometimes when you install a new version of
dotnet
sdk, it hits thePATH
.For those who encountered the issue after updating their Visual Studio or .NET Core package this is due to updates made in .NET Core 3 by removing
dotnet ef
from .NET Core and making it a separate package which can be installed via:For reference see this answer and this breaking change
For anyone struggling with this issue on Jetbrains Rider, I tried all the solutions listed on this page and eventually went into VS and ran the dotnet tool install --global dotnet-ef --version 3.0.0 command there and then reopened in Rider and it worked.
Note to readers: If you haven't install
dotnet ef
, you need to install it first:dotnet tool install --global dotnet-ef
. The question-asker already did that. You need to do that first before the rest of this answer can help.How to fix this
For Linux and macOS, add a line to your shell's configuration:
bash
/zsh
:csh
/tcsh
: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 thePATH
.What's going on?
The .NET Core 3.0 (preview) version of this failure is much more illuminating:
The second and the third one both refer to
dotnet
trying to find adotnet-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:
So, you should add
$HOME/.dotnet/tools/
to your$PATH
.But also note this part from docs:
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 commanddotnet 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:
Regarding the path fix:
Be aware this adds the path to the User PATH, not the System PATH environment variable. When firing off a "Developer Command Prompt" or "Developer Powershell" from Visual Studio, it does not use User path variable. You'll need to add it to the System environment variable as well.
Also, you'll need to restart VS before the change takes effect.