question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Have to change present working directory to project in solution to use EF Core CLI tools

See original GitHub issue

I have installed EF Core in a library project which is then referenced in my ASP.NET Core application.

When finally I got the package Microsoft.EntityFrameworkCore.Tools.Dotnet installed, I was unable to use the dotnet ef commands until or unless I change my present working directory in Package Manager Console to that project.

Project Structure

`

  • Project
    • Project.Lib
      • Project.Data
      • Other Libraries
    • Project.Web
      • Project.Web.Portal
      • Other Web Projects `

The present working directory is set to Project and the Default Project in Package Manager Console is set to Project.Data.

Steps to reproduce

Follow the project structure mentioned above and then try to run the following command after installing the Microsoft.EntityFrameworkCore.Tools.Dotnet package:

dotnet ef

Expected Behaviour

PM> dotnet ef

Entity Framework Core .NET Command Line Tools 1.0.1-rtm-10418

Usage: dotnet ef [options] [command]

Options:
  --version        Show version information
  -h|--help        Show help information
  -v|--verbose     Show verbose output.
  --no-color       Don't colorize output.
  --prefix-output  Prefix output with level.

Commands:
  database    Commands to manage the database.
  dbcontext   Commands to manage DbContext types.
  migrations  Commands to manage migrations.

Use "dotnet ef [command] --help" for more information about a command.
PM> 

Current Behaviour

PM> dotnet ef
dotnet : No executable found matching command "dotnet-ef"
At line:1 char:1
+ dotnet ef
+ ~~~~~~~~~
    + CategoryInfo          : NotSpecified: (No executable f...and "dotnet-ef":String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 

Workaround

Change present working directory to Project.Lib/Project.Data:

PM> cd Project.Lib/Project.Data

Now If I use the dotnet ef command, it works perfectly fine.

Further Details

I’m creating this issue because, in Entity Framework 6, it doesn’t matter in which project EF is installed. I could simply use EF 6 commands from the Package Manager Console without changing my present working directory. I just had to make sure the Default Project option of the Package Manager Console is set to the class library project which has EF 6 installed.

I’m curious whether this behavior is intended or a consequence of ‘everything-as-a-package’ pattern .NET Core follows.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
bricelamcommented, Jul 17, 2017

We strongly recommend using the PMC commands (Add-Migration, Update-Database, etc.) inside NuGet’s Package Manager Console since they provide a more integrated experience. Install the Microsoft.EntityFrameworkCore.Tools package to use them.

0reactions
humzakhancommented, Jul 17, 2017

@ajcvickers Hello there, the PMC commands works perfectly fine. Just started to use them, and yes you’re right, none of the tutorials available online use the PMC commands. All of them use the .NET CLI ones. This was the major reason I didn’t know about their compatibility with EF Core and Npgsql.

Read more comments on GitHub >

github_iconTop Results From Across the Web

EF Core Error - No project was found. Change the current ...
...I get the following Error. ... No project was found. Change the current working directory or use the --project option. I even tried...
Read more >
Have to change present working directory to project in ...
I just had to make sure the Default Project option of the Package Manager Console is set to the class library project which...
Read more >
How to run EF Core commands when your entities are in a ...
You can do this both with dotnet cli or EF Core PowerShell commandlets ... Change the current working directory or use the --project...
Read more >
EF Core tools reference (.NET CLI)
Works with the current project selected in the Package Manager Console without requiring that you manually switch directories. Opens files ...
Read more >
EF Core tools reference (Package Manager Console)
Reference guide for the Entity Framework Core Visual Studio Package Manager Console.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found