Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

There is a circular dependency in the target dependency graph involving target "DockerBuildServiceReferences"

I'm trying to add docker support to an existing ASP.Net (Core) web application.

Up to this point, all I've done is right click my solution and then clicked on Add > Docker Support. When I then try to start debugging using docker I get the following error:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(170,5): error MSB4006: There is a circular dependency in the target dependency graph involving target "DockerBuildServiceReferences".

I've checked the Microsoft.VisualStudio.Docker.Compose.targets file and I can't see any circular dependency involving DockerBuildServiceReferences, in fact searching through the entire file it's only mentioned in two places:

  <!--
  ***********************************************************************************************

  Docker Compose Project Targets

  ***********************************************************************************************
  -->

  <UsingTask TaskName="CleanWorkspace" AssemblyFile="$(DockerBuildTasksAssembly)" />
  <UsingTask TaskName="EnsureMsVsMonExists" AssemblyFile="$(DockerBuildTasksAssembly)" />
  <UsingTask TaskName="EnsureVsDbgExists" AssemblyFile="$(DockerBuildTasksAssembly)" />
  <UsingTask TaskName="GetServiceReferences" AssemblyFile="$(DockerBuildTasksAssembly)" />
  <UsingTask TaskName="PrepareForBuild" AssemblyFile="$(DockerBuildTasksAssembly)" />
  <UsingTask TaskName="PrepareForLaunch" AssemblyFile="$(DockerBuildTasksAssembly)" />

  <PropertyGroup>
    <BuildDependsOn>
      DockerSetDevelopmentMode;
      DockerPrepareForBuild;
      DockerGetServiceReferences;
      DockerBuildServiceReferences;
      $(BuildDependsOn);
      DockerComposeBuild;
      DockerPrepareForLaunch;
    </BuildDependsOn>
    <CleanDependsOn>
      DockerSetDevelopmentMode;
      DockerCleanWorkspace;
      $(CleanDependsOn);
      DockerGetServiceReferences;
      DockerCleanServiceReferences;
    </CleanDependsOn>
  </PropertyGroup>

  <PropertyGroup>
    <DockerComposeProjectPath>$(MSBuildProjectFullPath)</DockerComposeProjectPath>
  </PropertyGroup>

And:

  <!--
  ***********************************************************************************************

  TARGET : DockerBuildServiceReferences

  ***********************************************************************************************
  -->

  <Target Name="DockerBuildServiceReferences">
    <PropertyGroup>
      <DockerServiceReferenceTarget Condition=" '$(DockerDevelopmentMode)' == 'Regular' ">DockerPackageService</DockerServiceReferenceTarget>
      <DockerServiceReferenceTarget Condition=" '$(DockerServiceReferenceTarget)' == '' ">Build</DockerServiceReferenceTarget>
    </PropertyGroup>
    <MSBuild Projects="@(DockerServiceReference)"
             Targets="$(DockerServiceReferenceTarget)"
             Properties="Configuration=$(Configuration);Platform=$(Platform);BuildingInsideVisualStudio=false"
             Condition=" '@(DockerServiceReference)' != '' " />
  </Target>

I've also tried creating a new ASP.NET Core app from scratch and added docker support to that, it works perfectly. Which leads me to believe this error is covering for something else.

I'm using Visual Studio 2017 and the output of docker version is as follows (if that helps at all):

Client:
 Version:      17.05.0-ce-rc1
 API version:  1.27 (downgraded from 1.29)
 Go version:   go1.7.5
 Git commit:   2878a85
 Built:        Wed Apr 12 19:43:25 2017
 OS/Arch:      windows/amd64

Server:
 Version:      17.03.1-ce
 API version:  1.27 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   c6d412e
 Built:        Fri Mar 24 00:00:50 2017
 OS/Arch:      linux/amd64
 Experimental: true

Any ideas would be greatly appreciated!

like image 857
KidCode Avatar asked Jun 02 '17 13:06

KidCode


People also ask

How do you fix a circular dependency problem?

There are a couple of options to get rid of circular dependencies. For a longer chain, A -> B -> C -> D -> A , if one of the references is removed (for instance, the D -> A reference), the cyclic reference pattern is broken, as well. For simpler patterns, such as A -> B -> A , refactoring may be necessary.

How do I remove circular dependency?

To reduce or eliminate circular dependencies, architects must implement loose component coupling and isolate failures. One approach is to use abstraction to break the dependency chain. To do this, you introduce an abstracted service interface that delivers underlying functionality without direct component coupling.

How do I find circular dependencies?

By running a cli command npx madge --circular --extensions ts ./ we can quickly get a list of circular dependencies of all . ts files in current directory and its subdirectories. That's it! Now you see where you have circular dependencies and can go and fix it.

What are circular dependencies among servers and how can they be avoided?

A circular dependency occurs when two classes depend on each other. For example, class A needs class B, and class B also needs class A. Circular dependencies can arise in Nest between modules and between providers. While circular dependencies should be avoided where possible, you can't always do so.


2 Answers

For others who get this error and @VMAtm answer doesn't resolve. It can also happen if you are running the migrations commands in your solution folder, a level above your .csproj and dockerfile. Make sure you are in the project folder when you run migrations.

like image 173
Xaxum Avatar answered Nov 05 '22 10:11

Xaxum


According this thread and this answer, such situation may occur if you have Dockerfile and the project file (.csproj) not in the same folder, or you have a solution file (.sln) and project file (.csproj) in the same folder.

You've probably created a solution and startup project for it in the same directory, which will lead to docker circular reference. Try to re-create your project with separate folder and redo all the steps.

like image 37
VMAtm Avatar answered Nov 05 '22 11:11

VMAtm