Version your Visual Studio Builds by Git Commit Hash

Semantic versioning is great, but more often than not, when I'm looking at a folder of deployed binaries, I want to know the git commit hash of the source code that was used to generate them (a versioned container might be better in some cases, but that's not applicable in every situation at the moment).

A simple way to accomplish this is to generate a "version.txt" file at build time that will eventually be deployed with the code. Visual Studio makes it pretty easy to automatically generate this version.txt file with it's built in "build events". Simply add the following line to the "Post-build event command line:" textbox, and a version.txt file will appear in your build output directory with the current commit hash after a successful build.

"C:\Program Files\Git\bin\git.exe" rev-parse HEAD > "$(ProjectDir)$(OutDir)version.txt"




If you'd like to generate this file after an Azure Kudu deployment, see here: https://aaron-hoffman.blogspot.com/2017/01/azure-kudu-deployment-version-number.html


Hope this helps!
Aaron





Comments

Popular posts from this blog

Search iPhone Text Messages with SQLite SQL Query

How to Turn Off Microsoft Arc Touch Mouse Scroll Sound Vibration

Configure SonarAnalyzer.CSharp with .editorconfig, no need for SonarCloud or SonarQube