Reputation: 2009
I have a MAUI application with Android and iOS projects. When I build this application using Azure DevOps script I would like to automatically change application version.
How can I do that?
Upvotes: 3
Views: 2172
Reputation: 2009
In your MAUI app .csproj file, add the following directives:
<Target Name="UpdateAndroidAppVersion">
<XmlPoke XmlInputPath="Platforms\Android\AndroidManifest.xml" Namespaces="<Namespace Prefix='android' Uri='http://schemas.android.com/apk/res/android' />" Query="manifest/@android:versionCode" Value="$(VersionCode)" />
<XmlPoke XmlInputPath="Platforms\Android\AndroidManifest.xml" Namespaces="<Namespace Prefix='android' Uri='http://schemas.android.com/apk/res/android' />" Query="manifest/@android:versionName" Value="$(VersionNumber).$(BuildNumber)" />
</Target>
<Target Name="UpdateIOSAppVersion">
<XmlPoke XmlInputPath="Platforms/iOS/Info.plist" Query="//dict/key[. = 'CFBundleVersion']/following-sibling::string[1]" Value="$(BuildNumber)" />
<XmlPoke XmlInputPath="Platforms/iOS/Info.plist" Query="//dict/key[. = 'CFBundleShortVersionString']/following-sibling::string[1]" Value="$(VersionNumber).$(BuildNumber)" />
</Target>
In your azure-pipelines.yml script, at the top level, declare variables, to control version representation (particular variable values are shown just for example):
variables:
- name: versionNumber
value: "2023.1"
- name: buildNumber
value: $[counter(variables['versionNumber'], 0)]
- name: versionCode
value: $[counter('versionCode', 1)]
Then, in your yml-script, separately for android and ios jobs, declare the following MSBuild directives:
Android job directive:
- task: MSBuild@1
displayName: "Update Android App Version"
inputs:
solution: '**/MyMAUIApplication.csproj'
msbuildArguments: '/t:UpdateAndroidAppVersion /p:VersionNumber="$(versionNumber)" /p:VersionCode="$(versionCode)" /p:BuildNumber="$(buildNumber)"'
iOS job directive:
- task: MSBuild@1
displayName: "Update iOS App Version"
inputs:
solution: '**/MyMAUIApplication.csproj'
msbuildArguments: '/t:UpdateIOSAppVersion /p:VersionNumber="$(versionNumber)" /p:VersionCode="$(versionCode)" /p:BuildNumber="$(buildNumber)"'
Upvotes: 8