Last active
May 14, 2019 19:55
-
-
Save milolav/d1d7d2f37d275df2134ceae3eddf157a to your computer and use it in GitHub Desktop.
I was trying to figure out how to have autoincrement for c# projects that will work in the background, that works locally and that will not change on every build allowing you to build an app with the version stored in source control. And the result is this pre-commit script. It’s not perfect but it works for me. To use, put the file into .git\ho…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Update AssemblyFileVersion in every AssemblyInfo.cs if the files in solution | |
# change with the build part of the version number to be year & day of the year | |
# and the revision part with to be 1 & hour & minute. | |
# For example v1.0 commited at 15/06/2017 at 03:47 will become 1.0.17166.10347 | |
# | |
# Known issues: does not work with subfolder changes | |
list_files() { | |
for f in $(git diff --staged --name-only) | |
do | |
dir=$(dirname $f) | |
find $dir -name "AssemblyInfo.cs" | |
done | |
} | |
build=$(date +%y%j) | |
rev=1$(date +%H%M) | |
for f in $(list_files | sort | uniq) | |
do | |
sed -i -e 's/AssemblyFileVersion(\"\([0-9]\+\)\.*\([0-9]\+\)*\.*\([0-9]\+\)*\.*\([0-9]\+\)*")/AssemblyFileVersion("\1\.\2\.'$build'\.'$rev'")/' $f | |
git add $f | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment