Bug 44475 - "Cycle in target dependencies detected" error when using AfterTargets and DependsOnTargets
Summary: "Cycle in target dependencies detected" error when using AfterTargets and Dep...
Status: CONFIRMED
Alias: None
Product: Tools
Classification: Mono
Component: xbuild ()
Version: 4.4.2 (C7SR1)
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-09-19 04:50 UTC by Andrew Arnott
Modified: 2016-09-19 14:51 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 44475 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Andrew Arnott 2016-09-19 04:50:48 UTC

    
Comment 1 Andrew Arnott 2016-09-19 04:55:18 UTC
If any MSBuild target expresses both a DependsOnTargets and an AfterTargets for the same target, xbuild complains about a cycle. But this pattern is not only allowed in MSBuild, but it's useful, as a way to guarantee that one target always follows another, whether the first or second target is built from the command line. Here is a sample repro project:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="One" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
 <Target Name="One" />
 <Target Name="Two" DependsOnTargets="One" AfterTargets="One" />
</Project>

xbuild test.proj

Project "/mnt/c/Users/andarno/Documents/Visual Studio 2015/Projects/ConsoleApplication21/ConsoleApplication21/test.proj" (default target(s)):
: error : Error building target Two: Microsoft.Build.BuildEngine.InvalidProjectFileException: Cycle in target dependencies detected
  at Microsoft.Build.BuildEngine.Target.BuildOtherTargets (IEnumerable`1 targetNames, System.Action`1 missing_target, System.Boolean& executeOnErrors) <0x7ff703f0 + 0x00187> in <filename unknown>:0
  at Microsoft.Build.BuildEngine.Target.BuildDependencies (System.Boolean& executeOnErrors) <0x7ff70000 + 0x002a7> in <filename unknown>:0
  at Microsoft.Build.BuildEngine.Target.BuildActual (System.String built_targets_key, System.Boolean& executeOnErrors) <0x7ff8f860 + 0x001fb> in <filename unknown>:0
Done building project "/mnt/c/Users/andarno/Documents/Visual Studio 2015/Projects/ConsoleApplication21/ConsoleApplication21/test.proj".-- FAILED

Build FAILED.
Errors:

/mnt/c/Users/andarno/Documents/Visual Studio 2015/Projects/ConsoleApplication21/ConsoleApplication21/test.proj (default targets) ->

        : error : Error building target Two: Microsoft.Build.BuildEngine.InvalidProjectFileException: Cycle in target dependencies detected
  at Microsoft.Build.BuildEngine.Target.BuildOtherTargets (IEnumerable`1 targetNames, System.Action`1 missing_target, System.Boolean& executeOnErrors) <0x7ff703f0 + 0x00187> in <filename unknown>:0
  at Microsoft.Build.BuildEngine.Target.BuildDependencies (System.Boolean& executeOnErrors) <0x7ff70000 + 0x002a7> in <filename unknown>:0
  at Microsoft.Build.BuildEngine.Target.BuildActual (System.String built_targets_key, System.Boolean& executeOnErrors) <0x7ff8f860 + 0x001fb> in <filename unknown>:0

         0 Warning(s)
         1 Error(s)
Comment 2 Alexis Christoforides 2016-09-19 14:51:33 UTC
Hi Andrew, we are currently working on moving from MSBuild to xbuild.When the transition is complete, xbuild will be deprecated.