简体   繁体   中英

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?

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" .

If you want to do things automatically when you build a solution (either debug, release or both), Visual Studio has custom build events/steps which you can use to fire off a program or script to do whatever you want. The answer by hansmaad maybe isn't exactly what you want because there is no "auto-increment for each build", rather I assume the idea is to put SVN's version number of some file into a source file that gets compiled in. This makes sense to me because it allows you to tie a build to some source snapshot in SVN.

I think merging these two ideas (auto build increment and source controlled version file) is a little problematic... what happens when two developers start with version X and both build and update the version to X+1? Which one should take precedence when committing. I suppose it would be however committed their changes last, but that doesn't necessary carry any meaning, in my opinion. In other words, version Y on my machine is not the same as version Y on my co-workers machine.

It makes more sense to me to have a release process that marks the build with an auto-incrementing version, rather than have it auto-increment for every developer's build.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM