Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 917
Anupam Yadav Avatar asked Oct 01 '22 02:10

Anupam Yadav


1 Answers

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.

like image 164
Micah Zoltu Avatar answered Oct 12 '22 22:10

Micah Zoltu