1
votes

I have a solution with 3 projects as follows:

-Project.Api (A .net-core project which contains startup.cs and connection string)

-Project.Service (A .netstandard project which contains migrations, DbContext, etc)

-Project.Domain (A .netstandard project which contains the entities)

I am getting this error when trying to add new migrations from cli by running this command:

cd Project.Api     
dotnet ef migrations add DoSth

Your target project 'Project.Api' doesn't match your migrations
assembly 'Project.Service'. Either change your target project or
change your migrations assembly. Change your migrations assembly by using DbContextOptionsBuilder. E.g. options.UseSqlServer(connection, b => b.MigrationsAssembly("Project.Api")). By default, the migrations assembly is the assembly containing the DbContext. Change your target project to the migrations project by using the Package Manager Console's Default project drop-down list, or by executing "dotnet ef" from the directory containing the migrations project.

Besides, I am not using visual studio and I have to work with cli.

When I change the migrations assembly in the Startup.cs to 'Project.Api', the command runs with no error, but the problem is that the migrations are added under the 'Project.Api' and I don't want this because I want them under the 'Project.Service'.

I also tried to change the target assembly to 'Project.Service', but I got this error:

Startup project 'Project.Service.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 EF Core Tools with .NET Standard projects, see https://go.microsoft.com/fwlink/?linkid=2034781

1

1 Answers

1
votes

All I had to do was to change my working directory to the one that contains the migrations, then execute the command to add migrations and specify my startup project.

cd Project.Service

dotnet ef migrations add Add_Admin --startup-project ../Project.Api/Project.Api.csproj