Unable to use dotnet ef command in cli

asp.net-core ef-core-2.0 entity-framework entity-framework-core


I'm using ASP.NET Core 2.2 in a MVC web applicattion. I can use add-migration and update-database in my PMC and they work fine. BUT when I use their CLI commands in Windows Power Shell like dotnet ef migrations add InitMig they don't work and give this error:

The application to execute does not exist

To make it clear, I adressed the exact project. So there is no problem about directions. but still dotnet ef commands don't work.

I read this Microsoft article and it says I don't need to add any package in my project for NET Core 2.2 apps, to CLI commands work. Microsoft article

But I added that package to my project to test if dotnet ef works, like this:

         <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.3" />

so dotnet ef command works and gave its version and the unicorn. Now the problem is I can't use any commands even dotnet ef migrations list the error I get in CLI is:

Unable to create an object of type 'MainDbContext'. For the different patterns supported at design time,

any dotnet ef command in CLI reuslts in this error. As I mentioned before these commands work fine in PMC.

If u need any part of my project just let me know. I'll share it here.

7/10/2019 12:47:26 PM

Popular Answer

Check that you are running ef in the correct version of the sdk.

dotnet --version

You can specify the version by creating a global.json file in the root of your project.

  "sdk": {
    "version": "2.2.301"
9/5/2019 3:43:12 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow