14

Trying to use "dotnet ef" command in Package Manager Console. the PMC is cd to the .csproj directory, and still getting:

dotnet : Specify which project file to use because this 'C:\Users\PC-NAME\Source\Repos\TestProject\Test" contains more than one project file.
At line:1 char:1

dotnet ef migrations add TestMigration
  + CategoryInfo          : NotSpecified: (Specify which p...e project file.:String) [], RemoteException
  + FullyQualifiedErrorId : NativeCommandError

Tried use -p / --p and point to the .csproj file / directory - still same error.

Using .NET CORE, MVC project, Latest EF Core 2.0.2 version.

There's no so much valuable data on the internet about that problem, just a wild guess that dotnet ef command is looking for .exe file to run on.

Hoping for help.

user3181843
  • 175
  • 1
  • 2
  • 10
  • 1
    Why not just use the [EF Core PMC commands](https://learn.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell)? – bricelam Mar 19 '18 at 16:24

4 Answers4

2

If your project contains more than one .csproj file you should move them to another directory other than the project folder and run again your commande line.

In my case I have two .csproj in the project folder : CoreWebApplication.csproj and CoreWebApplication-backup.csproj so I moved the CoreWebApplication-backup.csproj and I kept the CoreWebApplication.csproj

dotnet ef ... -p CoreWebApplication.csproj -s CoreWebApplication.csproj

  • it was a little more involved than this. after removing the folder, I got another error ref: https://stackoverflow.com/questions/57066856/command-dotnet-ef-not-found ; after installing it, run clean and build solution. then ran dotnet ef in Package manager Console. it finally runs for me. – Dhruv Jul 27 '23 at 04:52
1

You need to specify your startup project and your data project using --startup-project and -p respectively.

dotnet ef migrations add TestMigration -p <path-to-your-project-with-your-db-context>.csproj --startup-project <path-to-your-project-with-your-program.cs>.csproj
Willie
  • 46
  • 5
0

In my case I had this Docker compose project created earlier on Visual Studio for MAC which included docker-compose.dcproj file in my folder. I had to move "docker-compose.dcproj" file to another folder before it worked. You can also delete that file cos I don't think it is useful anyway.

command that worked for me is below for scaffold

dotnet ef dbcontext scaffold 'Server=localhost;Database=<DatabaseName>;User=<username>;Password=<password>;TrustServerCertificate=True;' Microsoft.EntityFrameworkCore.SqlServer -p projectName.csproj -s projectName.csproj -o Data
Dasylva
  • 1
  • 3
-3

You'll need to specify both -p and -s:

dotnet ef ... -p ThisOne.csproj -s ThisOne.csproj

where

-p  --project <PROJECT> The project to use.
-s  --startup-project <PROJECT> The startup project to use.

EF Core .NET Command-line Tools

t3chb0t
  • 16,340
  • 13
  • 78
  • 118
bricelam
  • 28,825
  • 9
  • 92
  • 117
  • I filed issue [#11330](https://github.com/aspnet/EntityFrameworkCore/issues/11330) to make this experience better. – bricelam Mar 19 '18 at 20:38
  • 4
    I'm trying to use this method, still providing `-p` and `-s` arguments doesn't resolve an issue. Typing `dotnet ef -p BlazorApp1.csproj -s BlazorApp1.csproj` returns "Specify which project file to use..." error. Paths to project are ofc correct, I navigated to project folder – Piotrek Feb 15 '20 at 16:13
  • 1
    Note: it seems you'll get this same exact error text if you don't have `dotnet-ef` installed and in your PATH, even if you _do_ specify a project and/or startup project. – Kit Grose Mar 06 '20 at 09:14
  • 3
    I get the same error. I just set /home/yuri/.dotnet/tools/ to my PATH. And when I run `dotnet ef -p myProject.csproj -s myProject.csproj`, it return to me `Specify which project file to use because this '/home/yuri/Documents/csharp' contains more than one project file.`. How can I solve this problem? – Yuri Melo Nov 06 '20 at 00:07
  • 2
    Same with 5.0.0 tools. Specifying both doesn't work. – r590 Feb 03 '21 at 21:32