Change version number during build

I need the version of my delphi project to be the same as another project (and not delphi) as part of the script assembly. Is there a way to control the version number without going through the IDE, for example a compiler command line parameter or something like that? Thanks

+6
source share
2 answers

Include Type String

{$R 'version.res'} 

in your project. Create a version.rc file with your version information. You will need to create the resource yourself in older versions of Delphi using brcc32. In newer versions of Delphi you can use

 {$R 'version.res' 'version.rc'} 

so that the IDE automatically creates it for you.

The simplest version.rc will look something like this:

 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, see MSDN in the VERSIONINFO structure.

+12
source

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 advantage of using multiple #INCLUDE statements is that you can leave the RC file alone, and then simply change (or even automatically generate) * .txt include files that look like this:

 Ver_Num_Application.txt: #define VER_NUM_APPLICATION 6 Ver_Num_Library.txt: #define VER_NUM_LIBRARY 156 

Note that now you must delete the * .res files before starting the build in order to force the linker to regenerate them from (possibly modified) version numbers.

+2
source

All Articles