Running dotnet ef migrations for class library gives error MSB4006

entity-framework-core

Question

I have an ASP.NET Core Web Application (.NET Framework) project targeting .NET Framework 4.6.2.

I have introduced Entity Framework into the web project and have set up and run

dotnet ef migrations add Initial

from the web project directory. The migration is created, all is good.

I want to refactor the code so that my entities and db context are in a class library instead. So I have created a separate Class Library (.NET Framework) project, also targeting .NET Framework 4.6.2.

Still from the web project directory I run

dotnet ef migrations add Initial --startup-project . --project ..\MigrationTest.Entities

where MigrationTest.Entities is my class library.

This time I get:

C:\Projects\Experiments\MigrationTestNoIdentity\MigrationTest.Entities\obj\MigrationTest.Entities.csproj.EntityFrameworkCore.targets(4,5): error MSB4006: There is a circular dependency in the target dependency graph involving target "GetEFProjectMetadata". [C:\Projects\Experiments\MigrationTestNoIdentity\MigrationTest.Entities\MigrationTest.Entities.csproj] Unable to retrieve project metadata. Ensure it's an MSBuild-based .NET Core project. If you're using custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, Use the --msbuildprojectextensionspath option.

It isn't a .NET Core project, so I try creating a .NET Core project instead. Running the migrations command then gives:

C:\Program Files\dotnet\sdk\1.0.3\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.Common.targets(73,5): error : Project 'C:\Projects\Experiments\MigrationTestNoIdentity\MigrationTest.Entities.Core\MigrationTest.Entities.Core.csproj' targets '.NETCoreApp,Version=v1.1'. It cannot be referenced by a project that targets '.NETFramework,Version=v4.6.2'. [C:\Projects\Experiments\MigrationTestNoIdentity\MigrationTest.Entities.Core\MigrationTest.Entities.Core.csproj] C:\Program Files\dotnet\sdk\1.0.3\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.targets(92,5): error : Cannot find project info for 'C:\Projects\Experiments\MigrationTestNoIdentity\MigrationTest.Entities.Core\MigrationTest.Entities.Core.csproj'. This can indicate a missing project reference. [C:\Projects\Experiments\MigrationTestNoIdentity\MigrationTest.Web\MigrationTest.Web.csproj]

And of course, the Core project cannot be referenced by the .NET project.

Is what I am trying to do a supported scenario? Is there some problem with my command line usage? Something else?

1
10
4/27/2017 10:44:19 AM

Popular Answer

It's worth checking to ensure you have the EF Tools package installed.

Open the Package Manager console in Visual Studio and execute:

Install-Package Microsoft.EntityFrameworkCore.Tools

Then try your dotnet ef <commands> again.

3
6/19/2018 9:18:47 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow