Post build event is started before build

Mar 20, 2009 at 12:45 PM
Hi dave,

i have to use a post build event. Unfortunatley docproject somehow starts this event not after the build but before. Is this a known issue? Is there a workaround?

Greetings

Marc
Coordinator
Mar 21, 2009 at 8:53 AM
Hi Marc,

Edit the project file and override the AfterBuildHelp target instead of the AfterBuild target.

- Dave
Coordinator
Mar 21, 2009 at 6:41 PM
Hi Marc,

This is the expected behavior if you use the Properties | Build | Post-build event command line field.  The reason this happens is because the internal post-build event target is executed before DocProject's MSBuild task (see the DaveSexton.DocProject.targets file in the installation's bin folder).  This means that the assembly output will always be built before help is built.  The project's assembly output is required during help builds because it defines the project's registered Build Process Component (see the BuildProcess.cs|vb file in your DocProject or DocSite).

When implementing the .targets file, I considered all existing VS build-extensibility features as being related to the project's assembly output and provided additional points of extensibility that are specific to help builds (again, see the .targets file for details).  Therefore, you should think of the post-build event (and the AfterBuild target) as pertaining to the assembly being built by the project, which occurs before DocProject builds the help.

To execute a command after the help is built, you should override the AfterBuildHelp target.  Here's an example portion of a DocProject project file showing a regular post-build event, which doesn't work as one might expect because the target that executes the PostBuildEvent property is part of the project's assembly build process:

<PropertyGroup>

  <PostBuildEvent>

    echo ************************************************************

    echo POST-BUILD ASSEMBLY

    echo ************************************************************

  </PostBuildEvent>

</PropertyGroup>

<!--EndFragment-->
Here's an AfterBuildHelp target override that will work as expected:

<Target Name="AfterBuildHelp">

  <PropertyGroup>

    <PostBuildEvent>

      echo ************************************************************

      echo POST-BUILD PROJECT/HELP

      echo ************************************************************

    </PostBuildEvent>

  </PropertyGroup>

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

</Target>

<!--EndFragment-->
As you can see in the example above, I've moved the previously defined PropertyGroup that defines the PostBuildEvent property into the AfterBuildHelp target and used the Exec command to execute it.  Note that you can use a different property name if you'd like; e.g., PostBuildHelpEvent.

Alternatively, and this is my preferred approach, you are no longer restricted to command-line build events because you can use your project's Build Process Component to quickly and easily execute code (written in the language of the project) before or after the process and before, instead of and after each individual build step.  You can also add your own dynamic build steps.  This approach will not require you to modify the project file either, which is another advantage.  Here's an example C# snippet that outputs the same information as the previous example by overriding the BuildCompleted method in the build process component of a C# DocProject:

public override void BuildCompleted(BuildContext context)

{

  TraceLine();

  TraceLine("Total Time Elapsed: {0}", DateTime.Now - buildStart);

  TraceLine("************************************************************");

  TraceLine("POST-BUILD PROJECT/HELP (BPC)");

  TraceLine("************************************************************");

}

<!--EndFragment-->
- Dave
Mar 25, 2009 at 2:45 PM
Edited Mar 25, 2009 at 2:46 PM
hi dave,

thx it worked. But I dont have used the buildprocess.cs because i dont know how to access the environment variables like $(ProjectDir).

Greetings

Marc


Coordinator
Mar 25, 2009 at 7:24 PM
Hi Marc,

To access the project directory use something like the following code in any of the BuildProcess method overrides:

 

 

string projectDir = context.ProjectDirectory;

<!--EndFragment-->
- Dave