Edit
While continuing to research the topic, I have encountered some gotchas in my first answer. For this project, executing pre-build commands in Visual Studio is conflicting with other team members due to the hard coded path for the git bash terminal varying per workstation. To remedy this, I have introduced the idea of utilizing git hooks, running a Shell Script upon a post-commit action in git. This method will ensure the task at hand will be accomplished universally, point to the local git bash on each workstation, alleviating the potential to break the build in case the git bash path varies (which is a likely case).
Here is my new solution
navigate in your local repo .git > hooks > post-commit.sample
and replace with the following
revision=$(git rev-parse --short HEAD);
build=$(git rev-list HEAD --count);
version=$"{"$'"build":''"'$build$'"'$","$'"revision":'$'"'$revision$'"'$"}";
echo $version > "YourWebProject\version.txt";
Ensure to rename pre-commit.sample
to pre-commit
which will make the script now executable upon the action. Once executed, we will have a generated text file structured like the following JSON object
{
"build":"# representing your git commit count",
"revision":"abbreviated hash for last commit"
}
Create your Angular controller
function VersioningCtrl($scope, $http) {
$http.get('version.txt')
.success(function (data) {
if (data && status === 200) {
$scope.version = {
build: data.build,
revision: data.revision
}
}
});
}
Markup
<div data-ng-controller="VersioningCtrl">
Version 0.0.{{ version.build }}.{{ version.revision }}
</div>
Another gotcha
Due to the nature of this file being generated on the fly, I found it beneficial to include it within the git ignore file which was causing previous issues with git prompting me to always commit and track the new file.
I find this solution to be a bit more universal and efficient