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

前端 未结 6 1984
萌比男神i
萌比男神i 2020-12-28 13:28

I am using Visual Studio 2015 and dotnet core and trying to develop an EF Core Code First project using Sqlite and this documentation / tut

相关标签:
6条回答
  • 2020-12-28 14:07

    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

    0 讨论(0)
  • 2020-12-28 14:12

    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.

    0 讨论(0)
  • 2020-12-28 14:14

    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.

    0 讨论(0)
  • 2020-12-28 14:15

    It simply Means that

    YOU ARE NOT IN CURRENT PROJECT DIRECTORY

    I was facing the same issue when scaffolding existing database of MySql using this.

    Command I was executing:

    dotnet ef dbcontext scaffold "Server=123.1.1.1;Uid=abc;Pwd=abc;Database=myDB;Connection Timeout=20;Persist Security Info=False;Port=3306;Allow User Variables=True;Connect Timeout=120;" MySql.Data.EntityFrameworkCore -o Models
    

    Causing the same error , then I checked current working directory inside package manager console and found incorrect.

    In my case

    Mean I was not in current project directory then after switching directory

    cd SSGCApp

    Now you are in project directory all good to run the Command.

    0 讨论(0)
  • 2020-12-28 14:19
    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
    0 讨论(0)
  • 2020-12-28 14:21

    Instead of:

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

    try:

    "tools": {
          "Microsoft.EntityFrameworkCore.Tools.DotNet": {
          "version": "1.0.0-preview3-final"
      }},
    
    0 讨论(0)
提交回复
热议问题