8

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.

Community
  • 1
  • 1
Paul Alexander
  • 31,970
  • 14
  • 96
  • 151

2 Answers2

3

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>
Ross Johnston
  • 368
  • 1
  • 2
  • 7
1

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?

Sayed Ibrahim Hashimi
  • 43,864
  • 17
  • 144
  • 178
  • 1
    Here's what I'm trying to do: modify AssemblyVersion, do all the building, and as a final step revert AssemblyVersion to what it was. There does not appear to be a nice way of doing this. – Roman Starkov Jan 22 '11 at 19:11
  • romkyns: I'm doing the exact same thing. The way to do it is to override the `CoreBuild` target in your own csproj file, with an additional `OnError` attribute to specify that the `AfterBuild` target should be run if the build fails. That way, the `AfterBuild` target will run on every build, regardless of success or failure. See http://stackoverflow.com/a/5169881/278185 for info on overriding the `CoreBuild` target. – Dave May 18 '12 at 15:53