MSBuild in cooperation with ChangeResby Tiriss

How to use ChangeRes with MSBuild support in Delphi 2007 and higher

With the release of Delphi 2007, CodeGear has added MSBuild support to Delphi. This makes building your projects from the command line a lot easier. And so it also makes ChangeRes more useful (anyone can build their project from the command line now!).

To build your project and set its version from the command line, it is as easy as this:

 C:\Test\>ChangeRes MyProject FileVersion=..+1.*
 C:\Test\>MSBuild MyProject.dsproj

Where I assume that MyProject is in your C:\Test folder and that ChangeRes.exe and MSBuild.exe are in your PATH, so cmd.exe can find them. Of course you can also just put in the whole path of both tools.

Using ChangeRes as a pre build event

In newer Delphi IDE's (2007 and higher) you can also use pre and post build events. These are commands that are run before or after building your project. You can set them from your project options -> Build events dialog. In here you could also add ChangeRes as a pre build event to set the version even from the IDE, however this does not work!

I think this is because Delphi doesn't need files to be saved to disk before they can be compiled, and so in someway the IDE gives internal copies of the files used to MSBuild during build. ChangeRes does change the .res file of your project but if you build from the IDE the changed .res file is not used by the IDE. Instead it seems to be using the internal .res file (the one that is loaded when you open a project).

You can configure to use ChangeRes as a pre build event and it won't work when compiling from the IDE, it does work when compiling from the command line!

So if you configured ChangeRes as a pre build event, it is enough to do the following from the command line:

 C:\Test\>MSBuild MyProject.dsproj

For more info on MSBuild and what you can do with it, see here (MSBuild at MSDN).

© MMVIII Tiriss