开发者

ant BeforeTargets

开发者 https://www.devze.com 2023-03-11 20:13 出处:网络
In MSBuild there is a BeforeTargets attribute you can add to a target that allows you to run a target before the base target without having to alter the base target. I was wondering if ANT supported t

In MSBuild there is a BeforeTargets attribute you can add to a target that allows you to run a target before the base target without having to alter the base target. I was wondering if ANT supported this kind of functionality, or am I stuck having to redefine all my targets when I want to execute a target before another one ?

Thanks开发者_JS百科, Raul


You can use the depends attribute in (N)Ant:

<target name="target3" depends="target1,target2">

which is same as DependsonTargets in MsBuild I suppose. I would strongly discourage you from using Before/After Targets. If I run a target, after seeing the build file, and see that some extra target is run before / after it eventhough I did not see anything being said about the other targets, I would be very confused and sometimes, this can cause harm.


In MSBuild 4.0, there are BeforeTargets and AfterTargets attributes for targets. These specify a list of targets that are to be run before/after another target.

This is actually quite nice for specifying something to occur after a target defined in another targets file you don't have control over (such as Microsoft.Common.targets).

Example:

<Import Project="Microsoft.Common.targets" />
<Target Name="GetSourceFiles" BeforeTargets="Build">
    <Message Text="GetSourceFiles now executing" />
    ... execute your source control operations ...
</Target>
<Target Name="CopyOutputsForPublishing" AfterTargets="Build">
    <Message Text="CopyOutputsForPublishing now executing" />
    ... execute your copying operations ...
</Target> 

I've found these quite helpful.

Much more at: http://blogs.msdn.com/b/visualstudio/archive/2010/02/18/build-extensibility-with-net-framework-4.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消