views:

487

answers:

3

Multiple duplicates: http://stackoverflow.com/search?q=svnversion


I'm using TortoiseSVN with SVN Service running as a service on a windows server.

I would like the version / build number in the project to be updated as or after the project is committed. So that the correct version / build on the project will be reflected in several places such as log files, Resource tables, Help > About Etc...

Thanks...

A: 

You can do this in the build script and other places right before you make EXEs, install files, etc -

What I did to add it to my resources/version info was make a template file for my rc file, use the macro substitution, then add a call to SubWCRev in the prebuild step of my EXE's project.

See this

SubWCRev is a tool you can use for this.

$WCREV$ is the macro that gets replaced with the current svn revision.

Each template file is in the SVN repository but the actual files that get compiled/interpreted are generated from those. So just prior to building each generated output (exe, installer, release notes, etc) you would run the subwcrev tool and replace the macros.

Tim
A: 

Integrate something into your build process which writes the current SVN revision into a source file (e.g. revision.h which only contains a "const int revision = xxx;") which is not under version control (svn:ignore) and include this in the build.

Here's a very simple snippet to get the idea:

echo "const int revision = `svn info | grep Revision | cut -d":" -f 2`;" > revision.h
digitalbreed
that will not be accessible from resource files or install scripts. subwcrev is what you want.
Tim
I won't say that subwcrev isn't the right choice - it probably is for the OP's question. But my suggestion is accessible from resource files or install scripts indeed. You could also use "sed" to replace placeholders like subwcrev does. Plus, it would be cross-platform (Cygwin) and usable on CI build slaves where no graphical SVN client is installed.
digitalbreed
+1  A: 

You can use Revision tag.

Select one file which will contain some variable/constant with revision number. Add svn:keywords SVN property with Revision value to this file (RMB on file, TortoiseSVN->Properties->New, "svn:keywords" as name, "Revision" as value). Now inside this file every occurrence of "$Revision$" tag will be replaced with "$Revision: 7 $" for instance. Unfortunately this would be the version of this file only, so it'd have to be "touched" every time build number increases.

You can find more keywords working this way in SVN Book

leafnode
that is not a good way to do it. Use subwcrev.exe
Tim