13

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 2

17

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.

Sign up to request clarification or add additional context in comments.

Comments

6

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.

3 Comments

I figured it out earlier, but forgot to post the answer. Since you posted I'll give you the rep :)
Thanks for that :)
Also related to this, I created a web api project with docker compose with the template of VS 2022, and I was passing the wrong path to the --startup-project argument. I was in the root folder of my repository and was passing --startup-project MyApiProject --project MyDbContextProject when it should have been --startup-project MyApiProject/MyApiProject --project MyDbContextProject since the first folder contains the docker files, etc. and the project itself is in the inner folder.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.