What is the difference between 'DependsOnTargets' and 'AfterTargets'?

前端 未结 6 1147
孤街浪徒
孤街浪徒 2020-12-24 04:38

What is the difference between DependsOnTargets and AfterTargets? I can not distinguish these two.

6条回答
  •  温柔的废话
    2020-12-24 05:12

    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.

提交回复
热议问题