2

I am using Git for source control on a .NET project. Is there any way to include the current Git revision number in my EXE upon compile time?

I'd like to be able to have the revision number available for an "About" dialog, or similar. Perhaps there is a way to update Settings.vb right before build?

Brad
  • 159,648
  • 54
  • 349
  • 530
  • possible duplicate of [what is the git equivalent for revision number?](http://stackoverflow.com/questions/4120001/what-is-the-git-equivalent-for-revision-number) – Tim Schmelter Feb 05 '12 at 20:54
  • @TimSchmelter, That question has absolutely nothing to do with what I'm asking... I know how to get the revision number/hash. I'm just trying to get access to it within a compiled EXE. – Brad Feb 05 '12 at 22:22
  • Ok, then i might have misunderstood your question, cannot undo a close-vote, can i? – Tim Schmelter Feb 05 '12 at 22:28
  • @TimSchmelter, No, but that's no problem. It takes 5 people (or 1 mod) to close a question. – Brad Feb 05 '12 at 23:21

2 Answers2

1

An alternative to Lex Li's manual operation is to use the MSBuildVersioning mechanism (also available as a NuGet package). This requires a bit of tweaking in your csproj file (which the NuGet package will do for you), but it allows you to specify a "template" file which will be processed at build time to fill in whatever information you've decided to include in the template. While the documentation appears not to have been updated, the latest version works for Git, Mercurial and Subversion repositories. Available git-specific tags include REVNUM (the revision number), REVID (the hash, which is much more likely to be useful), DIRTY (are there uncommitted changes), BRANCH (the current branch) and TAGS (any tag(s) associated with the revision).

Richard J Foster
  • 4,278
  • 2
  • 32
  • 41
1

A possible approach is like this,

1 Programmatically printing git revision and checking for uncommitted changes

Following this post to learn how to query revision information from the working copy.

2 Modify your VB.NET project file so that before compiling it uses the query result above to update one of your file to include this information to your executable.

The second step needs some scripting skills. If you are familiar with MSBuild scripting, it should not be too hard.

Personally, I may write my own console application in .NET to perform the above commands, and then include it in PreBuild event.

Community
  • 1
  • 1
Lex Li
  • 60,503
  • 9
  • 116
  • 147