views:

2314

answers:

5

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?

+4  A: 

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

Adrian
Unfortunately, the $Rev$ keyword only gives the last revision that *the file in which is it appears* was changed.
Greg Hewgill
+3  A: 

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

Mike Thompson
+14  A: 

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
TortoiseSVN has a little helper utility named SubWCRev.exe, which finds the highest committed revision number of a working copy.
dummy
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
+3  A: 

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.

MattSmith
Good point: I forgot that was another benefit in our environment.
antik
+6  A: 

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.

rschuler