Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you call an overridden MSBuild target

Tags:

.net

msbuild

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.

like image 667
Paul Alexander Avatar asked May 11 '09 23:05

Paul Alexander


People also ask

Will MSBuild compile without any target?

If there are no initial targets, default targets, or command-line targets, then MSBuild runs the first target it encounters in the project file or any imported project files.

What is an MSBuild target?

A . targets file is an MSBuild-compliant XML file you can add to a project to allow customizing the build process. A . targets file can have <Target> nodes containing MSBuild scripts.

What are the common targets of MS build?

Common. targets is: BeforeRebuild , Clean , Build , and then AfterRebuild . Tasks that are inserted in one of these targets run before or after the core clean functionality is invoked. Tasks that are inserted in one of these targets run before or after the core publish functionality is invoked.

What is target file in Visual Studio?

targets files that contain items, properties, targets, and tasks for common scenarios. These files are automatically imported into most Visual Studio project files to simplify maintenance and readability. Projects typically import one or more . targets files to define their build process.


1 Answers

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.

like image 72
Sayed Ibrahim Hashimi Avatar answered Oct 04 '22 02:10

Sayed Ibrahim Hashimi