Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio project file difference between PostBuildEvent and AfterBuild target?

can someone explain the differences between these:

<Target Name="AfterBuild">     <!-- task here --> </Target> 

and:

<PropertyGroup> <PostBuildEvent>copy "$(ProjectDir)\..\lib\$(PlatformName)\x.dll" .</PostBuildEvent> </PropertyGroup> 

Thank you.

like image 986
Sako73 Avatar asked May 25 '11 17:05

Sako73


People also ask

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.

What is PostBuildEvent?

PostBuildEvent. This event executes after the build finishes.

What is MSBuild target?

A target element can have both Inputs and Outputs attributes, indicating what items the target expects as input, and what items it produces as output. If all output items are up-to-date, MSBuild skips the target, which significantly improves the build speed. This is called an incremental build of the target.

What are build events Visual Studio?

MSBuild is the build engine that Visual Studio uses to process your project file when it performs a build. A build event in the IDE results in an MSBuild target in the project file. You can use any MSBuild property that is available in the target in your project file (for example, $(OutDir) or $(Configuration) ) .


2 Answers

Both PostBuildEvent and AfterBuild are MSBuild targets. The difference between the two is the conditions around when they are invoked

  • AfterBuild: This runs as the last action in the Build target and does so irrespective of whether or not a build succeeds. It runs after PostBuildEvent (if it runs at all)
  • PostBuildEvent: This runs conditionally after a build completes. When it runs is very configurable but in general it will only run if a build successfully completes and produces new output.
like image 170
JaredPar Avatar answered Oct 12 '22 11:10

JaredPar


The PostBuildEvent property is able to hold a command that is passed as the Command attribute to an Exec task. Essentially you end up with a target that looks like this,

<Target Name="PostBuildEvent">    <Exec Command="$(PostBuildEvent)" /> </Target> 

You can configure the conditions when this will be run with a setting in the IDE, by default it only runs on a successful build.

The AfterBuild target is able to contain arbitrary MSBuild tasks, including one or more Exec tasks or any other task available to MSBuild, which allows for greater complexity.

In terms of when they are executed, the PostBuildEvent target runs just prior to "CoreBuild" while the "AfterBuild" target will run after "CoreBuild". If the placement is critical, you can make your own target and wire it into whereever in the build you need it to run, using the $(DependsOn..) declarations, or by specifying BeforeTargets and AfterTargets on your new target.

like image 21
Brian Kretzler Avatar answered Oct 12 '22 12:10

Brian Kretzler