What is the difference between DependsOnTargets
and AfterTargets
?
I can not distinguish these two.
While the other answers previously provided are correct, I think they failed to mention what I think is the primary benefit of AfterTargets
over DependsOnTargets
.
DependsOnTargets
has been around from the beginning of MSBuild. The problem with DependsOnTargets
, is that it requires a target author to explicitly allow for extensibility. This is done by defining a property that is used as the DependsOnTargets
value, as follows:
Dependency1;Dependency2
...
You could then add a dependency by modifying the SomeTargetDependsOnTargets
property as follows:
$(SomeTargetDependsOnTargets);Dependency3
The problem with this design, is that if the author had simply inlined Dependency1;Dependency2
rather than extracting it into a property, there would be no way to externally modify it to allow for customization.
AfterTargets
, on the other hand, doesn't require the original target author to have explicitly extracted the DependsOnTargets
value into a property to allow for extensibility.