Integrating revision number with .NET assembly

Alexander Gräf alex at graef.cc
Fri Aug 1 06:13:14 CDT 2008


> -----Original Message-----
> From: Giorgos Keramidas [mailto:keramida at ceid.upatras.gr] 
> Sent: Friday, August 01, 2008 11:15 AM
> To: Alexander Gräf
> Cc: mercurial at selenic.com
> Subject: Re: Integrating revision number with .NET assembly
> 
> "hg identify"?
> 

Thank you for that pointer. I created a simple .js-File:

Version.js:

var fso = new ActiveXObject("Scripting.FileSystemObject");
var shell = new ActiveXObject("WScript.Shell");
var hgIdentify = shell.Exec("hg identify --num");
var rev = hgIdentify.StdOut.ReadAll();
var outFile = fso.CreateTextFile("Version.cs", true);
outFile.WriteLine("using System.Reflection;");
outFile.WriteLine("[assembly: AssemblyVersion(\"0.1."+String(rev).replace("\n","").replace("+","")+".*\")]");
outFile.WriteLine("[assembly: AssemblyFileVersion(\"0.1."+String(rev).replace("\n","").replace("+","")+".0\")]");
outFile.Close();

And then included a pre-build event command line in Visual Studio 2008:

cd $(ProjectDir)Properties
cscript.exe Version.jse

It writes a Version.cs file with the current revision number in it. Not pretty but good enough for me...

Thanks,
Alex



More information about the Mercurial mailing list