0

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:

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

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.

Arian Shahalami
  • 1,369
  • 2
  • 13
  • 25

1 Answers1

0

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"
  }
}
ckal
  • 3,540
  • 1
  • 22
  • 21