Versioning an app from git tags

Hi,

Short question, probably a much longer answer :D
Has anyone used git tags to version their apps?

Explained:
Postulate git-flow named tages (eg v1.0.0), I'd like the AndroidManifest.xml of android projects (and the equivalent for iOS and WinPhone) and AssemblyInfo.cs to be automatically generated/updated using the latest tag and the number of commits since then.

Anyone know how to do this? Maybe even so that it works in Xamarin Studio as well?

Posts

  • tura08tura08 USMember
    edited November 14

    For Android and windows, I have done this with a powershell script that runs as a post build event. This sets the android versionNumber (versionCode) to the number of commits, and the versionName to the git tag description.

    Put the following script in your app project directory, call it "SetAndroidVersion.ps1":

    Write-Host "Updating AndroidManifest version information"
    $ManifestPath = (resolve-path .\..\..\Properties\AndroidManifest.xml)
    [xml] $xdoc = Get-Content $ManifestPath
    $versionName = (git describe --tags).ToString()
    $versionCode = (git rev-list --count HEAD).ToString()
    $xdoc.manifest.versionCode = $versionCode
    $xdoc.manifest.versionName = $versionName
    $xdoc.Save($ManifestPath)
    Write-Host "VersionCode set to $versionCode"
    Write-Host "VersionName set to $versionName"
    

    and put the following line as a post build event in the app properties:

    Powershell.exe -ExecutionPolicy Unrestricted -file "$(ProjectDir)SetAndroidVersion.ps1"

    After the app DLL is built you should see this is the console:

    >  Updating AndroidManifest version information
    >  VersionCode set to 2793
    >  VersionName set to 0.1.3-548-g9619f215
    

    and your manifest well be updated.

    P.S. I'd be interested if someone could convert this into a bash script so that this would work on VS4Mac as well.
    P.S.S You need git installed for this to work.

Sign In or Register to comment.