19

I'd like my .exe to have access to a resource string with my svn version. I can type this in by hand, but I'd prefer an automated way to embed this at compile time. Is there any such capability in Visual Studio 2008?

Gordon Wilson
  • 26,244
  • 11
  • 57
  • 60

5 Answers5

22

I wanted a similar availability and found $Rev$ to be insufficient because it was only updated for a file if that file's revision was changed (which meant it would have to be edited and committed very time: not something I wanted to do.) Instead, I wanted something that was based on the repository's revision number.

For the project I'm working on now, I wrote a Perl script that runs svnversion -n from the top-most directory of my working copy and outputs the most recent revision information to a .h file (I actually compare it to a saved reversion in a non-versioned file in my working copy so that I'm not overwriting current revision information at every compile but whether you chose to do so is up to you.) This .h file (or a number of files if necessary, depending on your approach) is referenced both in my application code and in the resource files to get the information where I'd like it.

This script is run as a pre-build step so that everything is up-to-date before the build kicks off and the appropriate files are automatically rebuilt by your build tool.

antik
  • 5,282
  • 1
  • 34
  • 47
  • 9
    TortoiseSVN has a little helper utility named SubWCRev.exe, which finds the highest committed revision number of a working copy. – dummy Oct 02 '08 at 06:36
  • Good to know! My team uses TortoiseSVN a great deal so it probably would have been good to know about the helper when I wrote the scripts. I may look into SubWCRev.exe at some point - it might be nice to drop the dependency on the normal Subversion distribution... – antik Oct 02 '08 at 13:51
  • 1
    One tip for others implementing this idea: Consider having your script write out a new version only if changes actually have been made locally; i.e. only if the value output by `svnversion` includes an "M" among the final set of characters. That will allow you to rebuild your project after a commit without the version number changing. (See [the `svnversion` documentation](http://svnbook.red-bean.com/en/1.7/svn.ref.svnversion.re.html) for a description of the format of its output.) –  Feb 17 '14 at 14:33
  • @SimonSouth We actually did something like that so would tell when we've encountered a modified, not versioned, build because we included the M on those builds. – antik Feb 17 '14 at 14:52
  • Does the repository revision number change after you commit your changes though? – rozina May 05 '14 at 08:04
16

How about using SubWCRev the command line tool that ships with TortoiseSVN. You create a template file with tokens in it like $WCREV$ $WCDATE$ etc. Then have a pre-build step that run SubWCRev on your template file to create the actual source file that is fed to the compiler.

Rodney Schuler
  • 2,158
  • 4
  • 23
  • 34
4

You can get SVN to embed it for you, if that will solve the problem. See the $Rev$ keyword on that page.

Adrian
  • 1,842
  • 13
  • 25
  • 5
    Unfortunately, the $Rev$ keyword only gives the last revision that *the file in which is it appears* was changed. – Greg Hewgill Sep 30 '08 at 00:36
4

Have a look at svn keyword substitution here. There is another SO question here which I found through google!

Community
  • 1
  • 1
Mike Thompson
  • 6,708
  • 3
  • 32
  • 39
3

antik's solution is the one we use. Be careful of using environment variables, the .h file ensures you can have a dependency which will cause any files that need it to be recompiled when the svn rev number changes.

Matthew Smith
  • 6,165
  • 6
  • 34
  • 35