Search code examples
c#.netentity-frameworkasp.net-core.net-core

I can't run dotnet ef on linux mint


My setup:

-- Linux --
Distributor ID: Linuxmint
Description: Linux Mint 21
Release: 21
Codename: vanessa

-- Dotnet SDK--
6.0.402 [/home/gilmar/.dotnet/sdk]

-- Dotnet Runtime --
Microsoft.AspNetCore.App 6.0.10 [/home/gilmar/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.10 [/home/gilmar/.dotnet/shared/Microsoft.NETCore.App]

-- Dotnet Tools --

ID do Pacote      Versão      Comandos 
---------------------------------------
dotnet-ef         6.0.10      dotnet-ef

I have trouble when I try to run the command dotnet ef. When I do it, returns the message below:

You must install .NET to run this application.

App: /home/gilmar/.dotnet/tools/dotnet-ef
Architecture: x64
App host version: 6.0.10
.NET location: Not found

Learn about runtime installation:
https://aka.ms/dotnet/app-launch-failed

Download the .NET runtime:
https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=linuxmint.21-x64&apphost_version=6.0.10

I modified my file .bashrc adding the lines below:

export PATH="$PATH:$HOME/.dotnet"
export PATH="$PATH:$HOME/.dotnet/tools/"

The folders in my directory:

gilmar@hp ~ $ whereis dotnet
dotnet: /home/gilmar/.dotnet/dotnet

gilmar@hp ~ $ whereis dotnet-ef
dotnet-ef: /home/gilmar/.dotnet/tools/dotnet-ef

I can run normally dotnet restore, dotnet new, dotnet build, etc, but I can't run dotnet ef

I tried:

dotnet ef
dotnet-ef
dotnet dotnet-ef
dotnet dotnet ef

I installed dotnet using the script from Microsoft at https://dot.net/v1/dotnet-install.sh

Anyone can help me? Thanks.


Solution

  • TLDR: To get dotnet-ef tool working, follow steps @ https://learn.microsoft.com/en-us/dotnet/core/tools/global-tools#install-a-local-tool

    For some reason, the global tools don't see the dotnet "location". .NET location: Not found I'm running on Linux Mint 22 Cinnamon.

    The fix/workaround:

    From within the solution directory, in a terminal, run

    dotnet new tool-manifest Creates a file at .config/dotnet-tools.json

    dotnet tool install dotnet-ef modifies the config file with some content

    dotnet tool restore Not sure if this is required, but I did it.

    dotnet dotnet-ef This is not the same as only running dotnet-ef on it's own.

    You should then see the lovely help message from dotnet-ef. At this point you can start creating your migrations. An example command that I've been using after this whole debacle:

    dotnet dotnet-ef migrations add [your_migration_name] --project [path_to_database_project].csproj --startup-project [path_to_startup_project].csproj --output-dir [sub_path_for_migrations]