I need to set the version of my delphi project to be the same as another project (not delphi) as part of a build script. Is there a way to control the version number without going thru the IDE, for example command line param of the compiler or something like that? Thanks
-
1This is why you should stop letting the IDE control the version resource and script your own version resource generation as a pre-build action – David Heffernan Jan 09 '13 at 18:48
-
@david do you have an instruction how to do that? – Z . Jan 09 '13 at 18:50
-
2Have a look at something like FinalBuilder, which allows you to set all your EXE's etc to the same build number, and ensure consistent build parameters etc. – mj2008 Jan 09 '13 at 18:54
-
1I write my own scripts for this. Using Python. You can indeed use a tool like FinalBuilder. I just prefer to do this myself. – David Heffernan Jan 09 '13 at 18:59
-
1FinalBuilder will definitely get the job done, but it has it's downsides. For me the greatest problem was its XML-based file format because it's not version-control friendly at all, and the fact that it's highly priced bloatware: it contains 10000 little tools that you'll never need, but there's no guarantee that the one tool you need is available. I used to write lots of tiny console applications to get around the missing tools (making it even less version-control friendly). It's price is justified in the ease of use it offers. If you don't want to invest TIME, that's the tool for the job. – Cosmin Prund Jan 09 '13 at 19:31
-
In the end I dropped FinalBuilder in favor of my own scripting language, a thing I call "ABS" and it looks almost like Pascal. Written with Delphi to compile Delphi applications. Of course, using Python or an other readily-available scripting language would be allot more practical. – Cosmin Prund Jan 09 '13 at 19:34
2 Answers
Include a line like
{$R 'version.res'}
in your project. And create a version.rc file with your version information. You will have to build the resource yourself in older Delphi versions using brcc32. In newer Delphi versions you can use
{$R 'version.res' 'version.rc'}
to have the IDE build it automatically for you.
The simplest version.rc would look something like:
1 VERSIONINFO
FILEVERSION 9999, 9999, 99, 18048
PRODUCTVERSION 9999, 9999, 99, 18048
FILEOS 0x00000004L // comment: VOS_WINDOWS32
FILETYPE VFT_APP
{
BLOCK "VarFileInfo"
{
VALUE "Translation", 0x409, 0x4E4 // comment: 0x4E4 = 1252
}
BLOCK "StringFileInfo"
{
BLOCK "040904E4"
{
VALUE "CompanyName", "Company Name\0"
VALUE "FileVersion", "9999.9999.99.18048\0"
VALUE "LegalCopyright", "Copyright \0"
VALUE "ProductName", "Product Name\0"
VALUE "ProductVersion", "9999.9999.99.18048\0"
VALUE "Homepage", "http://www.mydomain.com\0"
}
}
}
For more information, please refer to MSDN on the VERSIONINFO structure.

- 19,136
- 6
- 65
- 79
-
+1 for this as the solution that I use, but you do need to ensure that you delete version.res otherwise changes to version.rc are not noticed by the linker. – Brian Frost Jan 09 '13 at 20:59
-
@BrianFrost: what version of Delphi are you using? I have never had that problem. And you did turn off "include version info" in the project options? – Marjan Venema Jan 10 '13 at 07:33
-
My mistake. I see I needed to delete *.res when I moved to using #include in the *.rc for vernsion numbering, so then I was not modifying *.rc only my include file which has the actual version number alone. – Brian Frost Jan 10 '13 at 14:54
-
When you first set up this build system for your versioninfo .rc and .res you may encounter some weird compiler behavior that makes you scratch your head. [Why doesn't this work?!?!?](http://stackoverflow.com/a/32375628/512728) – Jan Doggen Sep 03 '15 at 14:06
-
This does work but wipes out existing version information manually entered for the EXE. Is it possible to continue to `Include version info` in the project properties and only modify parts of the version information using a compile-time switch? For example, you might set the `CompanyName` to "My Company" in the project properties and set only `InternalName` using your .rc based on the compile-time switch (eg. `{$IFDEF DBG}`). When I try this, the `CompanyName` is lost. – AlainD Feb 06 '18 at 22:18
-
1You can always write some utility to output the rc file and have that use the values from the project properties, @AlainD. It's actually how the content shown was produced. The first three numbers of the version reflect the branch for/from which the build was executed and the last is the last change number in the code repository. Only the release branches had actual release numbers for the version. That said, I can't think of any reason to make the version info have different information for debug or release builds - apart from reflecting that it is a debug or release build perhaps. – Marjan Venema Feb 07 '18 at 18:36
-
@MarjanVenema: Thanks, great comment. There are reasons why you might want a difference for some conditional define (like DBG or NDBG). For example, you might add or remove functionality based on the define. By also using the define to modify parts of VERSIONINFO you can identify what functionality has been added or removed without actually running the application. – AlainD Feb 09 '18 at 09:49
-
1Ah, @AlainD, changing the description for an exe or dll for example. That sounds like a good use case. Though I'd have to advocate against using conditional defines for including or excluding features. It leads to a combinatorial explosion on the number of exe's you should build and test. Much better to use [feature toggles](https://martinfowler.com/articles/feature-toggles.html) and control who or which type of person gets to see them through configuration and / or autorization roles. – Marjan Venema Feb 09 '18 at 13:21
-
@MarjanVenema: Thanks, very interesting read. I've used feature toggles in the past, but not known them by that name. – AlainD Feb 09 '18 at 17:16
Marjan gives an excellent answer above, but my answer takes the answer a little further. Consider this RC file:
VS_VERSION_INFO VERSIONINFO
#include "..\Ver_Num_Application.txt"
#define APPLICATION_NAME "My amazing project\0"
#define VER_NUM_ARTWORKS 4
#include "..\Libraries\Paslib32\Ver_Num_Library.txt"
#define COMPANY_NAME "My company\0"
FILEVERSION VER_NUM_ARTWORKS, VER_NUM_LIBRARY, VER_NUM_APPLICATION, 1000
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x9L
#else
FILEFLAGS 0x8L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", COMPANY_NAME
VALUE "FileDescription", APPLICATION_NAME
VALUE "LegalCopyright", "Copyright (C) "COMPANY_NAME
VALUE "ProductName", APPLICATION_NAME
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
The benefit in using the several #INCLUDE statements is that you can leave the RC file alone and then simply modify (or even auto-generate) the *.txt include files which look like:
Ver_Num_Application.txt:
#define VER_NUM_APPLICATION 6
Ver_Num_Library.txt:
#define VER_NUM_LIBRARY 156
Note that now you have to delete the *.res files before running your build to force the linker to regenerate them from (possibly changed) version numbers.

- 13,334
- 11
- 80
- 154
-
Wouldn't it be easier to just {$R ...} a different version.res/rc pair in the dpr using conditional defines there? IE `{$ifdef DEBUG}{$R version.res debugversion.rc}{$ELSE}{$R version.res version.rc}{$ENDIF}` It's not like the other info is gonna change often... – Marjan Venema Jan 10 '13 at 15:42
-
True. I guess I wanted a 'standard' RC file for all my projects and a file with *.txt extension that opened with notepad. – Brian Frost Jan 11 '13 at 09:12
-
1Aaww come'on Brian, a "standard" file I can understand, but a txt file? I am sure you know how to associate .RC files with Notepad as the default editor? ;-) – Marjan Venema Jan 11 '13 at 17:29
-
Do you have to disable version information for the project (and create a bespoke version resource file) or can you include version information and just modify the bits you want at compile-time? – AlainD Feb 06 '18 at 21:38