Help me understand, why target A (and D) is run while target B is not when MSBuild is invoked like this:
msbuild /target:C on this simple project (XML header omitted):
<Target Name="A" BeforeTargets="C"> <Message Text="Inside target A" /> </Target> <Target Name="B"> <Message Text="Inside target B" /> </Target> <Target Name="C" DependsOnTargets="B" Condition="'False'"> <Message Text="Inside target C" /> </Target> <Target Name="D" AfterTargets="C"> <Message Text="Inside target D" /> </Target> According to target build order:
- The
Conditionattribute of the target is evaluated. If theConditionattribute is present and evaluates tofalse, the target isn't executed and has no further effect on the build.- Before a target is executed, its
DependsOnTargetstargets are run.- Before a target is executed, any target that lists it in a
BeforeTargetsattribute is run.- ...
- After a target is executed or skipped, any target that lists it in an
AfterTargetsattribute is run.
which is why it is only logical to conclude that since predicate Before a target is executed is the same for both DependsOnTargets and BeforeTargets attributes, either both A and B should be run, or neither.
As far as my understanding goes, neither A nor B should be run since MSBuild is asked to run target C, which is conditional and Condition evaluates to false.
P.S. MSBuild 15.5.180.51428