Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Online automatic build version number increment and assembly patching

Tags:

azure-devops

i am using for a long time TeamCity. The AssemblyInfo patcher has the ability to patch all assemblyinfo files with a version number that is generated and incremented by TeamCity. Is this somehow possible with Visual Studio Online Build (the new scriptable, cross-platform one)?

like image 404
Mantzas Avatar asked Oct 21 '15 18:10

Mantzas


1 Answers

I've created a Bash Script which automatically replaces the version number in files such as AssemblyVersion.cs and can be used in a build-step, similar to the Power Shell Script published by Microsoft:

#!/bin/bash
# Sample call: ./ApplyVersionToAssemblies.sh ../Source/ AssemblyInfo.cs XamarinAndroid_1.0.0.1

echo "Script to automatically set the version-number in files (e.g. AssemblyInfo.cs)"

if [ $# -ne 3 ]; then
    echo "Usage: $0 path_to_search filename build_number"
    exit
fi

# Input is something like XamarinAndroid_1.2.3.4 and we want to extract only the 1.2.3.4
# See http://stackoverflow.com/a/19482947/448357 for more infos
VERSION_NUMBER="${3#*_}"

for file in $(find $1 -name $2); do
    echo "Replacing Version string in $file with ${VERSION_NUMBER}"
    sed -i '' -e 's/"[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*"/"'${VERSION_NUMBER}'"/' "$file"
done

First, create variables for Major and Minor version enter image description here

Second, set the build-number format to $(BuildDefinitionName)_$(Major).$(Minor).$(Year:yy)$(DayOfYear).$(Rev:rr) in the General tab of your build definition

enter image description here

And finally create a bash-script or a Powershell step with the scripts from above: enter image description here

like image 111
Alexander Pacha Avatar answered Oct 06 '22 18:10

Alexander Pacha