Programmatically updating FILEVERSION in a MFC app w/SVN revision number
Asked Answered
G

5

7

How do I go about programmatically updating the FILEVERSION string in an MFC app? I have a build process that I use to generate a header file which contains the SVN rev for a given release. I'm using SvnRev from http://www.compuphase.com/svnrev.htm to update a header file which I use to set the caption bar of my MFC app. Now I want to use this #define for my FILEVERION info.

What's the best way to proceed?

Gnni answered 20/9, 2008 at 18:12 Comment(0)
R
14

An .rc file can #include header files just like .c files can. I have an auto-generated version.h file, which defines things like:

#define MY_PRODUCT_VERSION    "0.47"
#define MY_PRODUCT_VERSION_NUM 0,47,0,0

Then I just have my .rc file #include "version.h" and use those defines.

VS_VERSION_INFO VERSIONINFO
 FILEVERSION MY_PRODUCT_VERSION_NUM
 PRODUCTVERSION MY_PRODUCT_VERSION_NUM
...
 VALUE "FileVersion", MY_PRODUCT_VERSION "\0"
 VALUE "ProductVersion", MY_PRODUCT_VERSION "\0"
...

I haven't tried this technique with an MFC project. It might be necessary to move your VS_VERSION_INFO resource to your .rc2 file (which won't get edited by Visual Studio).

Request answered 20/9, 2008 at 19:13 Comment(0)
C
3

Don't have enough points to comment yet, but whatever solution you choose keep in mind that FILEVERSION fields can only support a short integer. In our situation, our SVN revision was already above this and resulted in an invalid revision number in our FILEVERSION.

Contribution answered 8/4, 2009 at 18:38 Comment(1)
good point, perhaps you should split the revnum into 1000s and units; or use one of the other fields in the version block to store the revnum (as a string).Essence
A
1

In your application.rc file there is a version block. This block controls the version info displayed in the filesystem.

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1

You can programmatically update this file. Make sure to open and save the file as binary. We have had issues where edits are done as text and the file gets corrupted.

Airedale answered 20/9, 2008 at 18:44 Comment(0)
C
0

Changing VS_VERSION_INFO will reflect when you right click on the file in Explorer and see properties only.

If you want to show the current SVN revision number in the Caption bar, i would suggest:

  • Have a script get the version number and generate version.h file just with
#define SVN_VERSION_NO  xxx
  • Your project includes this version.h and uses that number to show in caption.
Colossal answered 20/9, 2008 at 19:5 Comment(0)
G
0

Maybe this can be helpful: Versioning Controlled Build

Gingili answered 22/12, 2008 at 7:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.