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

Viewed 7928

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!

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.

Related