Since version 2007 Delphi supports pre- and postbuild events for projects. If you only want to start programs or one batch file it’s a simple matter of adding the call to the respective section of the project options dialog. I use it to manage version numbers in the program resources and manifest files in prebuild and append translations and jcl debug info in postbuild and it works fine.
But a few days ago, I wanted, in addition to the above, to copy some dlls that the program needs to the output directory. So I went and added another batch file like this:
To my astonishment I found that only the first of the batch files was executed. After looking for the obvious problems (like typos, wrong paths etc.) and adding some debugging code to the batch files which confirmed the assumption, a question on StackOverflow seemed to be in order (which usually works much better than posting to the Embarcadero forums, because of the great guys frequenting it.) While I was waiting for an answer I continued to experiment and found one workaround:
%comspec% /c ..\..\buildtools\postbuild.cmd $(OUTPUTDIR)$(OUTPUTNAME)
%comspec% /c ..\copydlls.cmd $(OUTPUTDIR)
This was like a flashback to the bad old days of DOS, but it worked. I added this result to my question and while I was at it, checked for answers. Still none (but then it had been less than 5 minutes since I posted it. So I started looking for similar questions on StackOverflow that were not tagged Delphi but MSBuild. I found this answer and tried it:
call ..\..\buildtools\postbuild.cmd $(OUTPUTDIR)$(OUTPUTNAME)
call ..\copydlls.cmd $(OUTPUTDIR)
It also worked so I added it to my question as well. It looked like a more elegant solution than the %comspec% hack to me, so after more digging didn’t turn up anything else, I posted it as an answer to my own question and went on with my work.
Around half an hour later I looked at the question again and found that it had been answered by David Hefferman. I posted the question at 15:19 and got his answer at 15:36 which is not unusual for StackOverflow (At least this time he didn’t beat me to the solution, but hey, I was actively working on that problem while he was probably doing something completely different.).