Error MSB4006: There is a circular dependency -- Creating migrations
See original GitHub issueWhile trying to setup an EF Core project, the following error occurs when creating the migration.
<path>\foo\view\obj\view.csproj.EntityFrameworkCore.targets(4,5): error MSB4006: There is a circular dependency in the target dependency graph involving target “GetEFProjectMetadata”. [<path>\foo\view\view.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.
This is a typical MVVM WPF project, where the (EF Core) model, view-model(s), and (WPF) view(s) are each separated into their own projects. The model and view-model projects are NetStandard 2.0 projects, while the WPF is a .Net Framework desktop application. (I plan to change this to a Core project once Dotnet Core 3.0 is released.)
Here are the reproduction steps.
-
Create solution folder ‘foo’.
mkdir foo
-
Create solution ‘foo’.
<..\foo>dotnet new sln -n foo
-
Create a library project ‘model’.
<..\foo>dotnet new classlib -o model
-
Create a library project ‘modelviews’.
<..\foo>dotnet new classlib -o modelviews
-
Add projects to solution.
<..\foo>dotnet sln foo.sln add model/model.csproj
<..\foo>dotnet sln foo.sln add modelviews/modelviews.csproj
-
Open solution in Visual Studio. Add a WPF App (.NET Framework) project ‘view’ to the solution.
-
Change directory to ‘model’ project.
<..\foo>cd model
-
Install EF Core for SqlLite
<..\foo\model>dotnet add package Microsoft.EntityFrameworkCore.Sqlite
<..\foo\model>dotnet add package Microsoft.EntityFrameworkCore.Design
- Create model ‘model.cs’ in ‘model’ project.
using System;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
namespace Foo
{
public class Foo
{
public int Id { get; set; }
public int Name { get; set; }
}
public class Bar
{
public int Id { get; set; }
public int Name { get; set; }
}
public class FooContext : DbContext
{
public DbSet<Foo> Foos { get; set; }
public DbSet<Bar> Bars { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Data Source=foo.db");
}
}
}
- Create initial migration in the model project.
<..\foo>dotnet ef migrations add Initial --project model/model.csproj --startup-project view/view.csproj
This results in the error:
<path>\foo\view\obj\view.csproj.EntityFrameworkCore.targets(4,5): error MSB4006: There is a circular dependency in the target dependency graph involving target “GetEFProjectMetadata”. [<path>\foo\view\view.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.
What can be done to resolve or workaround this issue?
Version information: -Dotnet Core: 2.2.102 -Visual Studio: 15.9.4 -EF Core: 2.2.1 -OS: Windows 10 Pro (1809 – Build 17763.195)
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (5 by maintainers)
try to cd into nested project if you’re running it from top level directory
It sounds like
view.csproj
isn’t on of the new “SDK” projects (i.e. it doesn’t start with<Project Sdk="Microsoft.NET.Sdk">
).dotnet ef
will not work. Instead, use the PMC commands: