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

4.9k Views Asked by At

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?

5

There are 5 best solutions below

0
On

I had the same issue but didn't know that I had to cd into the "server" project and then run dotnet tool restore. That solved it for me.

1
On

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

2
On

I think I got it solved. I was lacking Microsoft.EntityFrameworkCore.Design.

  1. Installed Microsoft.EntityFrameworkCore.Design 3.0.0 using NuGet
  2. Ran dotnet tool restore which was successfully this time

    dotnet tool restore

Tool 'dotnet-ef' (version '3.1.0') was restored. Available commands: dotnet-ef

0
On

The dotnet ef tool is no longer part of the .NET Core SDK This change allows us to ship dotnet ef as a regular .NET CLI tool that can be installed as either a global or local tool.For example, to be able to manage migrations or scaffold a DbContext, install dotnet ef as a global tool typing the following command:

$ dotnet tool install --global dotnet-ef --version 3.0.0-preview4.19216.3 For more information, see this breaking change’s details.

0
On

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.