Search code examples
azure-devopsxamarin.androidyamlazure-pipelinesversion

How do I autoincrement Xamarin Android build and version numbers in Azure Pipelines?


I looked at the official documentation and couldn't find much,

Xamarin.Android
Build an Android app with Xamarin
task: XamarinAndroid@1 inputs:
#projectFile: '**/*.csproj'
#target: # Optional
#outputDirectory: # Optional
#configuration: # Optional
#createAppPackage: true # Optional
#clean: false # Optional
#msbuildLocationOption: 'version' # Optional. Options: version, location
#msbuildVersionOption: '15.0' # Optional. Options: latest, 16.0, 15.0, 14.0, 12.0, 4.0
#msbuildFile: # Required when msbuildLocationOption == Location
#msbuildArchitectureOption: 'x86' # Optional. Options: x86, x64
#msbuildArguments: # Optional
#jdkOption: 'JDKVersion' # Options: jDKVersion, path
#jdkVersionOption: 'default' # Optional. Options: default, 1.11, 1.10, 1.9, 1.8, 1.7, 1.6
#jdkDirectory: # Required when jdkOption == Path
#jdkArchitectureOption: 'x64' # Optional. Options: x86, x64

It feels like I am missing something since incrementing the version and build is required by Google Play Store and will need to be done on each release by everyone.

How do I autoincrement Xamarin Android build and version numbers in Azure Pipelines?


Solution

  • You have to set this in manifest file:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
              package="string"
              android:sharedUserId="string"
              android:sharedUserLabel="string resource" 
              android:versionCode="integer"
              android:versionName="string"
              android:installLocation=["auto" | "internalOnly" | "preferExternal"] >
        . . .
    </manifest>
    

    You can use token replace extension as follows:

    variables:
      major: 1
      number: $[counter(variables['major'], 100)]
    
    steps:
    - bash: echo $(minor)
    - task: qetza.replacetokens.replacetokens-task.replacetokens@3
      displayName: 'Replace tokens'
      inputs:
        targetFiles: |
          **/AndroidManifest.xml 
    

    with file like this:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
              package="string"
              android:sharedUserId="string"
              android:sharedUserLabel="string resource" 
              android:versionCode="#{number}#"
              android:versionName="string"
              android:installLocation=["auto" | "internalOnly" | "preferExternal"] >
        . . .
    </manifest>