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?
Migrations are enabled by default in EF Core. They are managed by executing commands. If you have Visual Studio, you can use the Package Manager Console (PMC) to manage migrations. Alternatively, you can use a command line tool to execute Entity Framework CLI commands to create a migration.
Delete your Migrations folder. Create a new migration and generate a SQL script for it. In your database, delete all rows from the migrations history table. Insert a single row into the migrations history, to record that the first migration has already been applied, since your tables are already there.
Possible reasons for this include: * You misspelled a built-in dotnet command. * You intended to execute a . NET program, but dotnet-ef does not exist. * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With