question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error MSB4006: There is a circular dependency -- Creating migrations

See original GitHub issue

While 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:closed
  • Created 5 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
chihabhajjicommented, Nov 27, 2021

try to cd into nested project if you’re running it from top level directory

4reactions
bricelamcommented, Jan 14, 2019

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:

Add-Migration Initial -Project model -StartupProject view
Read more comments on GitHub >

github_iconTop Results From Across the Web

Running dotnet ef migrations for class library gives error ...
Entities.csproj.EntityFrameworkCore.targets(4,5): error MSB4006: There is a circular dependency in the target dependency graph involving target ...
Read more >
Running dotnet ef migrations for class library gives error ...
Entities\obj\MigrationTest.Entities.csproj.EntityFrameworkCore.targets(4,5): error MSB4006: There is a circular dependency in the target dependency
Read more >
There is a circular dependency in the target ...
There is a circular dependency in the target dependency graph involving target "GetEFProjectMetadata" - Microsoft Q&A.
Read more >
Unable to retrieve project metadata. Ensure it's an SDK- ...
docker-compose.dcproj.EntityFrameworkCore.targets(4,5): error MSB4006: There is a circular dependency in the target dependency graph involving ...
Read more >
WPF + EFCore, unable to retrieve MetaData when trying ...
Hi, Having trouble creating migrations with EFCore 2.2.1 + WPF . ... error MSB4006: There is a circular dependency in the target dependency ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found