Get version number for Xamarin.Android and iOS

346 Views Asked by At

For creating my apk and ipa file for my Xamarin.Android and Xamarin.iOS projects with the pipeline I need the version number from the AndroidManifest.xml and Info.plist as a variable for use in my yaml config file. I'm changing the version number before pushing to my build branch.

What ways are there to get the version?

1

There are 1 best solutions below

0
Gabriel Weidmann On

I finally found a way:

The version number is in the AndroidManifest.xml:

<manifest ... android:versionName="1.0.1" ...>

If you got AAPT (Android Asset Packaging Tool, https://androidaapt.com) installed on your device you can use it for retrieving the version like this:

"%ANDROID_HOME%/build-tools/30.0.2/aapt.exe" dump badging "[your-apk-name].apk" | grep "versionName" | sed -e "s/.*versionName='//" -e "s/' .*//"

It will return just the version number:

1.0.1

Just run all of this in a script task in your build pipeline and assign the return value to a local or output variable.