Creating Pre- and Post-Build Events

In the Target Editor, you can add pre- or post-build events to your target. This lets you run command line events before or after the target is generated.

You can type commands directly into the fields. In addition, you can click the Insert Build Variable button for either the pre-build or post-build event to open a dialog. This lets you insert build-specific variables (e.g., target name, project name, project directory) into a command.

How to Create Build Events

  1. Open a target.
  2. On the Build Events tab of the Target Editor, enter a command in the Pre-Build Event Command or Post-Build Event Command text box. Be sure to use a separate line for each command.
  3. (Optional) If you need to insert a build variable into your command, click Insert Build Variable. In the dialog, do the following:

    1. In the text box, place your cursor where you want to insert a variable.
    2. From the Variable column, select the variable you want to add to the command. The variable's value is shown in the Value column.
    3. Click Insert to add the variable to the command.
    4. When you are finished adding variables to the command, click OK.
  4. Click Save the active file. to save your work.

Example — Copy Files to Output Folder

Let’s say you need to place copies of two PDF files—named “MyPDF1” and “MyPDF2”—into your Output folder after the target is generated.

Instead of doing this manually after the output is compiled, you open the target and select the Build Events tab. Then you enter a command in the Post-Build Event Command field. In this case, the command is as follows:

for %I in (C:\Users\myusername\Desktop\MyPDF1.pdf

C:\Users\myusername\Desktop\MyPDF2.pdf) do copy %I "$(OutputDirectory)"

With this particular command, Flare will copy the PDF files from your desktop, so that’s where you place these two original files. After you save your changes in Flare, you generate the target. When you look in the output folder in Windows, you will see the two PDF files.

Example — Create a Folder

Let’s say you want to automatically create a new folder on your desktop just before your target is generated.

First, you can open a simple text editor such as Notepad and type a command such as this:

You save the file as a batch (.bat) file. In the following example, we saved this batch file on our desktop, but you can save it anywhere.

Next, you open the target, select the Build Events tab, and in the Pre-Build Event Command field you enter the command that points to the batch file. In this case, the command is as follows:

C:/Users/myusername/Desktop/Create_Directory.bat

As soon as you build the target, a new folder named “MyDirectory” is added to the desktop:

Note If command line errors occur, they will be included in the build log. However, they will not prevent the project from compiling.