Could not execute because the specified command or file was not found.
after dotnet ef means the EF Core command-line tool is not installed where
you ran it. ef is not part of the SDK; install dotnet-ef as a
local tool for the project, or globally for your user.
In a project folder: dotnet new tool-manifest, then
dotnet tool install dotnet-ef with the version that matches your EF Core
packages. After that, dotnet ef --version answered in that folder.
The error
$ dotnet ef migrations list
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.
exit=1
Why it happens
When dotnet gets a word it does not know as a built-in command, it looks
for a tool named dotnet- plus that word, here dotnet-ef. The
three bullets are the three things dotnet tried, and the second one names
the missing program. The official SDK container image has no dotnet-ef,
so the command failed there, while on the PC that ran the container
dotnet tool list -g shows dotnet-ef 10.0.0 installed globally. A tool installed on one machine does
not come with the code to another.
A local tool is recorded in a manifest file, dotnet-tools.json, which
sits with the project and can be committed with it.
The fix
dotnet new tool-manifest
dotnet tool install dotnet-ef --version 10.0.12
dotnet ef --version
...
Tool 'dotnet-ef' (version '10.0.12') was successfully installed. Entry is added to the manifest file /tmp/EfApp/dotnet-tools.json.
$ dotnet ef --version
Entity Framework Core .NET Command-line Tools
10.0.12
exit=0
The install line says where the manifest went: on SDK 10.0.302 it was
dotnet-tools.json in the project folder itself. The output above it (cut
here) says the tool can be called as dotnet tool run dotnet-ef
or dotnet dotnet-ef; plain dotnet ef --version answered too.
Pick the tool version to match your Microsoft.EntityFrameworkCore
packages; the test used 10.0.12.
The manifest alone does not install anything. In a second fresh container holding only
dotnet-tools.json, dotnet ef --version failed with a different
message, Run "dotnet tool restore" to make the "dotnet-ef" command available.
After dotnet tool restore it answered 10.0.12. So another machine or a
Dockerfile needs dotnet tool restore after checkout, before the first
dotnet ef.
dotnet tool restore
Tool 'dotnet-ef' (version '10.0.12') was restored. Available commands: dotnet-ef
A newer version of tool 'dotnet-ef' is available (version '10.0.14'). Consider updating your manifest file.
Restore was successful.
The global alternative is dotnet tool install --global dotnet-ef. It is
fine on your own PC, but it is exactly what made the command work on one machine and
fail on another, so prefer the manifest for anything shared.
How it was reproduced
Inside a throwaway container from the cached
mcr.microsoft.com/dotnet/sdk:10.0 image (SDK 10.0.302), started with
docker run --rm so it was removed afterwards: a
dotnet new console project in /tmp/EfApp, then
dotnet ef migrations list. The fix was run in the same container, which
served only as a clean machine without the tool.
Frequently asked
- Why does dotnet ef say could not execute because the specified command or file was not found?
- The EF Core tool dotnet-ef is not installed for that folder or user. The SDK does not include it; install it as a local tool with a manifest, or globally.
- How do I install dotnet ef as a local tool?
- Run dotnet new tool-manifest in the project folder, then dotnet tool install dotnet-ef with the version that matches your EF Core packages, and commit the dotnet-tools.json file.
- Why does dotnet ef work on my PC but not in Docker?
- Your PC probably has a global install of dotnet-ef. The mcr.microsoft.com/dotnet/sdk:10.0 image does not include the tool, so install it there as a local tool from a manifest.
More decoded errors in the Fixes category. Once the tool runs, every command is in the dotnet ef commands reference.