echo using System.Reflection; > Properties\HGVersion.cs
for /f "delims=" %%a in ('hg id -i') do @set b=%%a
echo [assembly: AssemblyInformationalVersion("%b%")] >> Properties\HGVersion.cs
Yes, that third line is apparently how you get the results from running a command into an environmental variable in batch scripts. Aren’t batch scripts fun? Anyways, this script will run hg id -i, resulting in the hash code for your current changeset, and uses it to generate a file HGVersion.cs in your project’s Properties directory that reads like this:
Build the project once to run the script, then add the resulting HGVersion.cs file to your project, and make sure you add it to your .hgignore file too. Now your exe or dll will have its Mercurial changeset in the Product version field that you can see in Properties in Windows Explorer. As far as I can tell, it’s not possible for the user to change that normally, so it should be a durable way to mark what version your executable is. You can also retrieve it within your application, for About boxes and such, with the following:
.First() as AssemblyInformationalVersionAttribute)
I suppose you could also use this to check the build version of other assemblies that you’re using to prevent problems – it’s probably simpler than using strong names.