I was trying to figure out how to have autoincrement for c# projects that would work in the background, that would 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\hooks\ folder in your project.
#!/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 |
Top comments (2)
I've been trying to take an approach which provides some dev control and increasing version per commit.
Unlike yours the version is injected by the build system.
Versions and Testing
Jesse Phillips ・ Jan 11 ・ 3 min read
I'd say that versioning through build system is the correct way. Mine was pretty much just a simple hack that works offline and without any dependencies.