This question is a follow-up of this other one.
In that question, one mentions the usage of [assembly: AssemblyVersion(...)] to the file AssemblyInfo.cs file, and in the meanwhile I've found out that it's forbidden to execute any processing before such a line, the only thing which is allowed is something like:
[assembly: AssemblyVersion("1.0.0.0" + "-" + Namespace.Class.Attribute)], or:
[assembly: AssemblyVersion("1.0.0.0" + "-" + Namespace.Class.Method())]
Original question:
So my question: is there a Namespace.Class.Attribute or Namespace.Class.Method() which contains the commit hash (or sha or shortened sha) of a C# application?
Edit after more investigation
In the meantime I've learnt that the command git describe --always gives me the information I'm looking for, so what I need is something like:
[assembly: AssemblyVersion("1.0.0.0-" + Launch("git describe --always")]
... but how can I execute that Launch()?
I already know that I can launch a commandline command using System.Diagnostics.Process(), like this example:
System.Diagnostics.Process.Start(foldervar + "application.exe", "inputfile.txt");
... but this way does not catch the result of that command.
New question:
So, does anybody know a C# one-liner for launching commandline commands and getting their result?
Thanks in advance


Build Eventsfor a project from your solution. Take a look here: learn.microsoft.com/en-us/visualstudio/ide/…. There you can call a bat-file that runs git and stores a full version number in a text file. Then as another pre-build step, you can re-create a version file with the new content. Check this question for the version file creation example: stackoverflow.com/questions/26021684/….