简体   繁体   中英

How do you call an overridden MSBuild target

In MSBuild you can override a <Target /> from another file in your own. For example the AfterBuild target included in Microsoft.Common.targets file simply by defining your own Target with the same name:

<Target Name="AfterBuild">
    <!-- Do something different -->
</TargetName>

You'll see a note like this:

Overriding target "AfterBuild" in project "C:\\Windows\\Microsoft.NET\\Framework\\v3.5\\Microsoft.Common.targets" with target "AfterBuild" from project "XXXXX".

Is there any way to call the original AfterBuild target?

I'd like to do this to instrument certain complex default Targets and then execute the original behavior. Many targets like Build expose a BuildDependsOn property that can be used for this. Many others do not - and I'd like to override them without completely duplicating their content.

When an MSBuild script is processed it will also process the imported files. The result will be a single in memory canonical representation of the entire script. When a target is encountered that already exists the previous definition is discarded, therefore it is not possible to call the original target.

Sayed Ibrahim Hashimi

My Book: Inside the Microsoft Build Engine : Using MSBuild and Team Foundation Build

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM