Anupam Yadav
Anupam Yadav

Reputation: 4583

error MSB4006: There is a circular dependency in the target dependency graph involving target

I have following target on csproj file using VS2012, i want to run "Publish" on the project once the build has finished.

This gives me following error "error MSB4006: There is a circular dependency in the target dependency graph involving target "AfterBuild""

<Target Name="AfterBuild">
  <Message Text="Running Publish..." Importance="high"/>
  <MSBuild Projects="$(ProjectPath)" Properties="DeployOnBuild=true;PublishProfile=WebDeploy;CreatePackageOnPublish=True;VisualStudioVersion=11.0"/>
</Target>

i have tried replacing the MSBuild step with

<Exec Command="$(MSBuildBinPath)\MSBuild C:\MyProj.csproj /p:DeployOnBuild=true /p:PublishProfile=WebDeploy /p:CreatePackageOnPublish=True /p:VisualStudioVersion=11.0" ContinueOnError="false" />

Doing above results in build/publish being run over and over.

i have tried naming target different, calling it via another target to no avail.

How can i run "Publish" on the project without getting into repeated cycles? can this be done in another way?

Upvotes: 7

Views: 12643

Answers (2)

jonmeyer
jonmeyer

Reputation: 848

Previously I was building with Visual Studio and TFS Server, which worked fine, but when i moved to GO-CD the following code caused a circular dependency creating packages.

 <Target Name="CopyLinkedContentFiles" AfterTargets="Build" DependsOnTargets="PipelinePreDeployCopyAllFilesToOneFolder">
<Copy SourceFiles="%(Content.Identity)"
      DestinationFiles="%(Content.Link)"
      SkipUnchangedFiles='true'
      OverwriteReadOnlyFiles='true'
      Condition="'%(Content.Link)' != ''" />

Upvotes: 0

Micah Zoltu
Micah Zoltu

Reputation: 7432

If you only build in Visual Studio, then putting something like this into your csproj file (at the end) will work:

 <Target Name="Deploy" AfterTargets="Build">
   <MSBuild
     Projects="$(ProjectPath)"
     Targets="WebPublish"
     Properties="PublishProfile=LocalDeploy"
   />
 </Target>

However, if you build with with MSBuild this will result in a circular dependency. I have not yet figured out a solution that will allow you to publish on build that works in both Visual Studio and MSBuild.

Upvotes: 5

Related Questions