EF Core Error - No project was found. Change the current working directory or use the --project option

馋奶兔 提交于 2019-11-30 06:22:49
Gys Rademeyer

Instead of:

"tools": {
    "Microsoft.EntityFrameworkCore.Tools.DotNet":"1.0.0"
  },

try:

"tools": {
      "Microsoft.EntityFrameworkCore.Tools.DotNet": {
      "version": "1.0.0-preview3-final"
  }},

sometimes you need to change the current directory in console/terminal eg:

PM> cd E:\Projects\CrossTest\
PM> dotnet ef migrations add InitialMigration

and Align your package versions. Either use preview1 packages or preview2. Mix of those are not supported.

  1. Add the nuget package Microsoft.EntityFrameworkCore.Tools
  2. Add the nuget package Microsoft.EntityFrameworkCore.Design
  3. Right-click your project file, select Edit and then add the following to the ItemGroup that contains PackageReference nodes

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

(You can find the latest version by finding it in the Nuget Package manager)

  1. Open the Package Manage Console: Tools->Nuget Package Manager->Package Manager Console
  2. Type cd {path where your csproj file resides} (this is important)
  3. Now type dotnet ef migrations add InitialMigration

Just faced similar issue. Fixed by downgrading to 1.0.0-preview3-final

"tools": {
     "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.0.0-preview3-final",    
}

and changing --project param to --startup-project

dotnet ef --startup-project <PATH_TO_PROJECT_DIRECTORY> migrations add <MIGRATION_NAME>

In global.json I also downgraded version to

 "sdk": {
     "version": "1.0.0-preview2-003131"
 }

This might be a temp workaround before migrating to csproj.

The dotnet-ef command has moved.

You will need to add a reference to Microsoft.EntityFrameworkCore.Tools.DotNet AND Microsoft.EntityFrameworkCore.Design to your dependencies in project.json, then add Microsoft.EntityFrameworkCore.Tools.DotNet to the tools section and you should be good to go.

Cited from: http://errummwelluhh.blogspot.com

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!