1
votes

I have experience to use EF migrations in .NET MVC but after switching to .NET Core and CLI, now I cannot apply migrations using CLI. Here are the commands that I use, but I am not sure in which project I should open CLI.

Assume that I open CLI on the solution directory and there are 2 projects; Domain project contains Entities, and Infrastructure project contains Migrations folder:

add-migration

dotnet ef migrations add AddDateOfBirthField --project src\Domain 
--context ApplicationDbContext --output-dir src\Infrastructure\Migrations

Throws the following error:

Startup project 'Domain.csproj' targets framework '.NETStandard'. There is no runtime associated with this framework, and projects targeting it cannot be executed directly. To use the Entity Framework Core .NET Command-line Tools with this project, add an executable project targeting .NET Core or .NET Framework that references this project, and set it as the startup project using --startup-project; or, update this project to cross-target .NET Core or .NET Framework. For more information on using the Entity Framework Tools with .NET Standard projects, see https://go.microsoft.com/fwlink/?linkid=2034781

So, should I execute the command from another directory of CLI or use an extra flag e.g. --startup-project?

1
Does anybody else have no experience with Entity Framework Core?zertuc
--project src\Domain type is not .Net Core or .Net framework. That's why you are getting this error.Berkay
@Berkay Thanks amigo. How should I run that command? Could you post it according to the given info (Domain project contains Entities, and Infrastructure project contains Migrations folder:)zertuc
@Yogi Perfect !!! Many thanks amigo, it seems to be working.zertuc

1 Answers

0
votes

You will get this issue with using the Entity Framework Core tools in a .NET Standard Library: the EF Core tools don’t support the .NET Standard framework: they can only target .NET Core or .NET Classic (Full framework). To resolve this you need to create a dummy project with a dependency on the .NET Standard Library. You can find more details here and here.