Write the SVN version revision number to the program version information

Source: Internet
Author: User
Tags svn

The

Tsvn has a command-line program Subwcrev.exe. You can make some macro substitutions on a specified file, for example: Replace $WCREV $ with the current version number. This is the most useful. See   for more help;
 http:// Tortoisesvn.net/docs/nightly/tortoisesvn_zh_cn/tsvn-subwcrev-keywords.html
Take VC6 as an example, the version information of the file is saved in the RC file. Compile into res file, Then link with the other obj. Now the idea is. Edit the RC file and change the version number, such as 2.2.4.0, to 2.2.4. $WCREV $, before each link, use Subwcrev.exe to process the RC file and replace it with a macro. Then call Rc.exe to compile the replaced new file. Link together after generating res.

. Modify the RC file's Versioninfo interleaved as follows:
#ifdef _autoversion
FileVersion 2,2,4, $WCREV $
ProductVersion 2,2,4, $WCREV $
#else
FileVersion 2,2,4,0
ProductVersion 2,2,4,0
#endif
...
#ifdef _autoversion
VALUE "FileVersion", "2, 2, 4, $WCREV $/0"
VALUE "ProductVersion", "2, 2, 4, $WCREV $/0"
#else
VALUE "FileVersion", "2, 2, 4, 0/0"
VALUE "ProductVersion", "2, 2, 4, 0/0"
#endif

In fact, it adds conditional compilation. By default, _autoversion is not defined, using the original FileVersion, ProductVersion. If _autoversion is defined, the new version information is used.

. In the project properties, locate the Pre-Link page. in which add:
Subwcrev/subwcrev.exe. Myprogram.rc myprogram.rc_
rc.exe/l 0x804/fo "/release/myprogram.res"/d "_autoversion"/d "_afxdll" "Myprogram.rc_"

The first command handles MYPROGRAM.RC, generates MYPROGRAM.RC_
The second command compiles myprogram.rc_ to Myprogram.res, paying attention to its path.  This is the default path for the release version. The principle is that the res generated here replaces the original res file.

Press F7, build. The version information is now refreshed. Submit each time to SVN. Version will be updated.

But we can take it a step further. Writes version information, compile time, etc. to the About dialog box. In fact, the key or Pre-Link.
. Create a file buildtime.cpp with the following content:
Const CHAR*SZBUILDTIME = "Build on $WCNOW $";
Const char*szfullversion= "MyProgram 2.2.4. $WCREV $ $WCMODS? +:$ $WCMIXED? #:$";

. In the About dialog box OnInitDialog (), add:
extern const char* Szbuildtime;
extern const char* Szfullversion;
Setdlgitemtext (Idc_buildtime, szbuildtime);
Setdlgitemtext (Idc_version, szfullversion);

. In Pre-Link plus two:
Subwcrev/subwcrev.exe. Buildtime.cpp Buildtime_.cpp
CL/C/NOLOGO/FO/RELEASE/BUILDTIME.OBJ/MT Buildtime_.cpp

The same principle as the RC file. Replace first, then compile. Also ensure that the generated Buildtime.obj cover the original buildtime.obj

Done.
But one thing to note. The VC6 Resource Editor rebuilds the RC file every time the resource is edited. In other words, we will delete our modifications to RC. Have not found a good way, now only after each edit resources and then manually add the conditional compilation part. It is recommended that you add the version information after the project enters Beta. Because at this time the program's resources are generally not changed.

In addition, although here is VC6 as an example, but can also be applied to vc2003, vc2005 and other compilation environment.

PostScript: You can also consider using the program to automatically modify. Locate FileVersion, replace the later version with the FileVersion 2,2,4, $WCREV $, and then replace with Subwcrev. Then compile with RC. You do not have to define _autoversion macros.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.