Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Finally" target for MSBuild

Tags:

msbuild

Is there a way to run a certain target after all other targets have been run regardless of their success or failure?

try...finally equivalent in MsBuild is related, but only deals with a small group of targets. I need something for the whole package with dozens of sub builds.

like image 909
Paul Alexander Avatar asked Apr 17 '10 04:04

Paul Alexander


People also ask

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.

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.

Where is Microsoft common CurrentVersion targets?

NET projects are defined in the Microsoft. Common. CurrentVersion. targets file which can be found in the MSBuild bin directory.

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.


2 Answers

Maybe if you wrapped things in a top-level target using one or more CallTargets, then you could use an <OnError .../> task to run a final target?

<Target Name="CompleteBuild">
  <CallTarget Targets="Target1"/>
  <CallTarget Targets="Target2"/>
  <CallTarget Targets="FinalTarget"/>

  <OnError ExecuteTargets="FinalTarget"/>
</Target>
like image 60
Ross Johnston Avatar answered Sep 18 '22 23:09

Ross Johnston


There is no straight forward way of doing this. Usually in MSBuild it is hard to know the actual order of targets, only the relative order. What are you trying to do with this target?

like image 45
Sayed Ibrahim Hashimi Avatar answered Sep 22 '22 23:09

Sayed Ibrahim Hashimi