Each time a new version is built, the software version is automatically increased.

Source: Internet
Author: User
Tags tortoisesvn

Vc2005 uses the SVN version to generate the DLL and EXE file versions

Tortoisesvn has a subwcrev program. You can obtain the SVN version number corresponding to any path. And replace it with the file location.

Vc2005 resource files can control the generated binary file version.

Subwcrev can be called by using the command before vc2005 generation to obtain the latest SVN version number and write it into the generated binary file.

The program can also determine whether the called dll version is larger than itself. To control the non-calling of the corresponding dynamic library. The dependency can be ensured at a runtime layer.

To achieve this goal, you must

  • Obtain the version number of the current version library from SVN and write it to the resource file before each compilation.
  • After compilation, the version information is read when the installation package is installed.

Pay attention to the following two points:

1. The SVN tool can obtain the version number and update it to the project file.

If the source and target files are provided, subwcrev copies the source files to the target file and performs the following keyword replacement:

Table 5.2. List available command line switches

Keywords Description
$ Wcrev $ UseWorkReplace the highest submitted version in the replica
$ Wcdate $ Replace it with the date/time of the most submitted version. The default international format is used:yyyy-mm-dd hh:mm:ss. You can specifystrftime()Use a custom format, for example:$WCDATE=%a %b %d %I:%M:%S %p$. For a list of Characters in the format, seeOnline Reference.
$ Wcnow $ Replaced with the current system date/time. This can be used to indicate the build time. Time formatting can be used as described$WCDATE$.
$ Wcrange $ Replace the updated version range in the working directory. If the working directory is consistent, it is a single version. If the working directory contains a mixed version, or is outdated, or is intentionally updated to the version, the range will be displayed in a format like.
$ Wcmixed $ Used when a mixed version is availableTTextReplace$WCMIXED?TText:FText$Otherwise, useFTextReplace.
$ Wcmod $ If a local modification exists, useTTextReplace$WCMODS?TText:FText$Otherwise, useFTextReplace.
$ Wcurl $ Replace it with the version library address of the working directory passed to subwcrev.
$ Wcinsvn $ $WCINSVN?TText:FText$Is replacedTTextIf the entry is versioned, orFTextIf not.
$ Wcnedslock $ $WCNEEDSLOCK?TText:FText$Is replacedTTextIf the entry hassvn:needs-lockProperty set, orFTextIf not.
$ Wcislocked $ $WCISLOCKED?TText:FText$Is replacedTTextIf the entry is locked, orFTextIf not.
$ Wclockdate $ Replaced with the lock date. Time formatting can be used as described$WCDATE$.
$ Wclockowner $ Replaced with the name of the lock owner.
$ Wclockcomment $ Replaced with the comment of the lock.

The following example shows how the keywords in the template file are replaced in the output file.

// Test file for SubWCRev: testfile.tmplchar *Revision = "$WCREV$";char *Modified = "$WCMODS?Modified:Not modified$";char *Date     = "$WCDATE$";char *Range    = "$WCRANGE$";char *Mixed    = "$WCMIXED?Mixed revision WC:Not mixed$";char *URL      = "$WCURL$";#if $WCMODS?1:0$#error Source is modified#endif// End of file

After runningSubWCRev.exe path\to\workingcopy testfile.tmpl testfile.txt, The output filetestfile.txtWocould looks like this:

// Test file for SubWCRev: testfile.txtchar *Revision = "3701";char *Modified = "Modified";char *Date     = "2005/06/15 11:15:12";char *Range    = "3699:3701";char *Mixed    = "Mixed revision WC";char *URL      = "http://project.domain.org/svn/trunk/src";#if 1#error Source is modified#endif// End of file

 

Subwcrev.exe runs from the command line or script and uses command line parameter control.

SubWCRev WorkingCopyPath [SrcVersionFile DstVersionFile] [-nmdfe]

WorkingCopyPathIt is the path of the working copy to be checked. You can only use subwcrev for the working copy, instead of directly targeting the version library. This path can be an absolute path or a relative path of the working directory.

If you want to replace subwcrev with keywords, such as the version library version, address, and other fields, you need to provide a template fileSrcVersionFile, Output fileDstVersionFileIs the version after the template is replaced.

Several switches affect subwcrev. If multiple instances are used, they must be specified in a single group. For example-nm, Cannot be used-n -m.

Table 5.1. List available command line switches

Switch Description
-N If this switch is given, subwcrev will exitERRORLEVEL 7If the working copy contains local modifications. This may be used to prevent building with uncommitted changes present.
-M If this switch is given, subwcrev will exitERRORLEVEL 8If the working copy contains mixed revisions. This may be used to prevent building with a partially updated working copy.
-D If this switch is given, subwcrev will exitERRORLEVEL 9If the destination file already exists.
-F If this switch is provided, subwcrev will contain the last modified version of the folder. By default, only files are taken into account when the version number is obtained.
-E If this switch is given, subwcrev will examine directories which are encodedsvn:externals, But only if they are from the same repository. The default behaviour is to ignore externals.
-X If this switch is given, subwcrev will output the revision numbers in hex.
-X If this switch is given, subwcrev will output the revision numbers in Hex, with '0x 'prepended.
Reference this document http://tortoisesvn.net/docs/nightly/TortoiseSVN_zh_CN/tsvn-subwcrev.html

2. Execute a get version number operation before each build.

 

Take vc6 as an example. The version information of the file is stored in the RC file. compile it into the res file, and thenOthersOBJ link together. the current idea is. edit the RC file and change the version number to 2.2.4, for example, 2.2.4.0. $ wcrev $. Before each link, use subwcrev.exe to process the RC file and replace the macro. call rc.exe to compile the new file after replacement. link after RES is generated.

. Modify the versioninfo segment of the RC file 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, Conditional compilation is added. By default, _ autoversion is not defined. The original fileversion and productversion are used. If _ autoversion is defined, the new version is used.

. Find the pre-link page in the project properties. 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 processes myprogram. RC and generates myprogram. RC _
The second command compiles myprogram. RC _ as myprogram. res. Pay attention to its path. This is the default path of the release version. The principle is that the res generated here replaces the original res file.

Press F7, build. The current version information has been refreshed. Each submission to SVN will be updated.

However, we can go further. Write the version information and Compilation Time To the dialog box. In fact, the key is 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 $ wcmod? +: $ Wcmixed? #: $ ";

In the oninitdialog () dialog box, add:
Extern const char * szbuildtime;
Extern const char * szfullversion;
Setdlgitemtext (idc_buildtime, szbuildtime );
Setdlgitemtext (idc_version, szfullversion );

. Add two more items to pre-link:
Subwcrev \ subwcrev.exe. buildtime. cpp buildtime _. cpp
CL/C/nologo/FO \ release \ buildtime. OBJ/MT buildtime _. cpp

The principle is the same as that of the RC file. replace it first, and then compile it. Ensure that the generated buildtime. OBJ overwrites the original buildtime. obj.

Success.
But pay attention to it. the resource editor of vc6 re-generates the RC file after each resource editing. that is to say, the changes to RC will be deleted. no good method has been found. Now, you can only manually add the Conditional compilation part after each resource editing. we recommend that you add the version information after the project enters beta. at this time, the program resources will not change.

In addition, although vc6 is used as an example, it can also be applied to compiling environments such as vc2003 and vc2005.

Note: You can also consider using the program to automatically modify it. find fileversion, replace the following version with fileversion, 4, $ wcrev $, and then replace it with subwcrev. compile with RC. you do not need to define the _ autoversion macro.

 

Each time a new version is built, the software version is automatically increased.

Related Article

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.