Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autoversioning in C++ with Visual Studio 2008 and SVN

I am using MS Visual Studio 2008 to do some development work in C++ and currently we have a version function that returns a hard coded string representing the version number. I would like to figure out a way so that instead of a hard coded number, it could start from, say, 1 and increment by 1 every time I make a debug or release build (or even better, keep track of the debug version and release version numbers). Or if that is not possible, use the current date/time as the version number.

Note that because there will be several people working on the project and using the SVN, the code has to be computer independent (meaning that if I am currently on version 100, my colleague's last build was at version 90, then the next time (after I check in the code and my colleague pulls out the code), the version number of his next compile should be 101 rather than 91.)

Could you please help?

like image 614
AZhu Avatar asked Jan 12 '23 13:01

AZhu


1 Answers

If you are using TortoiseSVN you can use subwcrev.exe in a pre build event to write the current revision number to a source file.

Therefore, checkin a file version.template.hpp and add something like

  const string version = "13.12.0.$WCREV$";

Add a project pre build event

subwcrev.exe "$(SolutionDir)." "$(ProjectDir)version.template.hpp" 
             "$(ProjectDir)version.hpp"

and include the generated file #include "version.hpp".

like image 130
hansmaad Avatar answered Jan 19 '23 00:01

hansmaad