Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot list Entity Framework Migrations in Visual Studio 2019 due to dotnet ef dbcontext --json failure

I have an ASP.NET Core 3.0 project that uses .NET Core 3.0. I have recently upgraded VS 2019 to version 16.4.1.

I use Web Publish from Visual Studio to deploy the application on various environments, but this failed after the upgrade due to EF migrations (trying to find the db contexts failed):

dotnet ef dbcontext --json failure

Run "dotnet tool restore" to make the "dotnet-ef" command available.

I tried to understand what is wrong.

dotnet tool restore

Cannot find a manifest file. For a list of locations searched, specify the "-d" option before the tool name. No tools were restored.

dotnet tool install --global dotnet-ef

Tool 'dotnet-ef' is already installed.

dotnet tool list

Package Id Version Commands Manifest

(there are not items in this list)

dotnet-ef --version

Entity Framework Core .NET Command-line Tools 3.1.0

dotnet --version

3.1.100

Do I need to upgrade to upgrade everything to 3.1? I would like to postpone this if possible (I have to do this on multiple environments and it is scheduled at a later time).

Note: I also have Visual Studio 2017 and Entity Framework Migrations contexts are properly discovered when configuring the publishing profile.

Question: How to solve Cannot list Entity Framework Migrations in Visual Studio 2019 due to dotnet ef dbcontext --json failure?

like image 409
Alexei - check Codidact Avatar asked Oct 21 '25 07:10

Alexei - check Codidact


2 Answers

I had the same problem (after an update of visual studio 2019), on my pc there is this problem but in another pc no. The files are all equal (checked via git), VS2019 cache something somewhere and this is bad.

1 Check the default connection string is ok.

2 Check if dotnet ef is installed. In core 3.1 you must install: dotnet tool install -g dotnet-ef

3 Close VS, delete the folder <yourproject>/Properties (backup it if you want), open VS, clean solution and import the publish file again.

like image 195
Evilripper Avatar answered Oct 23 '25 18:10

Evilripper


Run

dotnet tool uninstall --global dotnet-ef

Run

dotnet tool install --global dotnet-ef

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

  • bash/zsh: (nano ./zshrc)

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

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

Source: https://stackoverflow.com/a/56876020/9324707

like image 43
Thomas Avatar answered Oct 23 '25 18:10

Thomas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!