Running robocopy as pre-build event?

This forum is for all Flare issues not related to any of the other categories.
Post Reply
oceanclub
Sr. Propeller Head
Posts: 277
Joined: Thu Oct 10, 2013 4:45 am
Location: Dublin

Running robocopy as pre-build event?

Post by oceanclub »

I tried a robocopy command following as a pre-build event but it doesn't appear to work:

robocopy ..\wiki Content\wiki /MIR

I then tried putting it into a prebuild.bat file at the same level as my project file and calling _that_ as a pre-build event command but that didn't work either.

Does anyone know how this might be accomplished within the target?

EDIT: For the Pre-Built Event Command field I've tried:

"$(ProjectDirectory)\prebuild.bat"

and

start "$(ProjectDirectory)\prebuild.bat"

The later caused a command window to pop up with nothing happening. I'm not sure I'm going wrong as based on the official help and also this page, a simple reference to a BAT file should work:

https://help.madcapsoftware.com/flare20 ... Events.htm

https://www.linkedin.com/pulse/one-flar ... -williams/

EDIT 2: According to Madcap this is a bug.....

P.
bgo
Jr. Propeller Head
Posts: 6
Joined: Mon Sep 09, 2019 8:39 am

Re: Running robocopy as pre-build event?

Post by bgo »

A few things I learned recently while trying to do something similar:

- Flare's build events start in the directory from which Flare was launched (Desktop, if you launched Flare from a shortcut there; the folder where your .flprj is, if you launched Flare by double-clicking the project file; etc.). So it's best not to make assumptions about what directory your build event commands (or the external scripts they call) start from. Therefore, start your build event with a cd command to the directory you want--e.g.

cd /D "$(ProjectDirectory)\..\my-scripts"

This might've been the problem with your "robocopy ..\wiki Content\wiki /MIR" command. What is .. relative to?

- Pre-build events start when the build starts and run concurrently with the build. So you can't depend on them to complete something before the Flare build needs it. If you really need something done before the build starts, don't use a pre-build event. Instead, use either a batch target or write an external script that does what you want first, then calls madbuild.exe to build your Flare project

- Robocopy doesn't like quoted paths with a trailing backslash. You usually need to use quotes around paths to correctly handle paths with spaces. So be sure to strip off any trailing backslash. Something like this in a batch file will do the trick:

if %myPath:~-1%==\ set myPath=%myPath:~0,-1%

See https://ss64.com/nt/robocopy.html

- The workaround in the Matty Williams LinkedIn post didn't work for me. I was trying to call my external script and pass it the Flare-provided variables, but whatever Flare is doing with quotes around commands in build events was messing it up. My script couldn't reliably parse out the arguments. So I gave up on passing command-line arguments, and instead wrote them to a file, which my external script could parse. Like this:

echo "$(ProjectName)"> args.txt
echo "$(ProjectDirectory)">> args.txt
echo "$(OutputDirectory)">> args.txt

Then in my external batch script, you can read them into variables from the args.txt file:

(
set /p projectName=
set /p projectDir=
set /p outputDir=
) < args.txt

- Spaces in paths are a pain, but if you want things to work in those cases, you must be aware of how or whether quotes are being used around paths.

Hope this helps the next poor soul who tries to use build events.
Post Reply