azure-devopsmauicicdappcenter

Distributing from AzureDevops to App Center shows all the releases with the same version 1.0 (1)


I have CI and CD pipelines on AzureDevops for Android application written in .NET Maui.

When the release shows up on AppCenter after CD is successfully run, the version of the release is the same for all of them even though that is not what was set for the version in the CI pipeline.

Releases on the AppCenter

Here is my bash script used for getting this version to the AssemblyInfo.cs file.

ANDROID_MANIFEST_FILE="AndroidManifest.xml"

        if [[ ${{ parameters.SetVersionCodeInManifest }} == True ]]
        then
          VERSION_CODE="$(Azure_DevOps_BUILD_ID)"

          echo "Updating Android build information. New version code $VERSION_CODE"

          sed -i '' -e 's/versionCode="1"/versionCode="'$VERSION_CODE'"/' $ANDROID_MANIFEST_FILE
        fi

        VERSION_NAME=$(App_BUILD_NUMBER)

        echo "Updating Android build information. New version name $VERSION_NAME"
        
        sed -i '' -e 's/versionName="[0-9.]*"/versionName="'$VERSION_NAME'"/' $ANDROID_MANIFEST_FILE

        cat $ANDROID_MANIFEST_FILE

        # Set AssemblyInfo
        assemblyInfoPath='assemblyinfo.cs'
        echo "assemblyInfoPath: $assemblyInfoPath"
        sed -i '' -e 's/"[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*"/"'$(App_BUILD_NUMBER)'"/' "$assemblyInfoPath"
        cat $assemblyInfoPath

Task result where this code block is executed:

Updating Android build information. New version code 72719
sed: can't read : No such file or directory
sed: can't read /Platforms/Android/AndroidManifest.xml: No such file or directory
Updating Android build information. New version name 1.0.0.7184
sed: can't read : No such file or directory
sed: can't read /Platforms/Android/AndroidManifest.xml: No such file or directory
cat: /Platforms/Android/AndroidManifest.xml: No such file or directory
assemblyInfoPath: Properties/assemblyinfo.cs
sed: can't read : No such file or directory
//------------------------------------------------------------------------------

using System;
using System.Reflection;

[assembly: System.Reflection.AssemblyMetadataAttribute("Microsoft.Maui.ApplicationModel.AppInfo.PackageName", "3486d78e-ccd6-4b01-8805-f784dfd27193")]
[assembly: System.Reflection.AssemblyMetadataAttribute("Microsoft.Maui.ApplicationModel.AppInfo.PublisherName", "User Name")]
[assembly: System.Reflection.AssemblyMetadataAttribute("Microsoft.Maui.ApplicationModel.AppInfo.Name", "My.App")]
[assembly: System.Reflection.AssemblyMetadataAttribute("Microsoft.Maui.ApplicationModel.AppInfo.Version", "1.0.0.7184")]
[assembly: System.Reflection.AssemblyCompanyAttribute("My.App")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.7184")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0+99823c39b76e2e934d222f88f256c57b37f1c3a0")]
[assembly: System.Reflection.AssemblyProductAttribute("My.App")]
[assembly: System.Reflection.AssemblyTitleAttribute("My.App")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.7184")]
[assembly: System.Runtime.Versioning.TargetPlatformAttribute("Windows10.0.22000.0")]
[assembly: System.Runtime.Versioning.SupportedOSPlatformAttribute("Windows10.0.17763.0")]

// Generated by the MSBuild WriteCodeFragment class.

Solution

  • The answer was that if you want your binaries to change version, .NET MAUI does not take them from assemblyinfo.cs but from .csproj file and properties ApplicationDisplayVersion for Version name and ApplicationVersion for VersionCode.

    I added a PowerShell task to my pipeline which updates the .csproj file:

    - task: PowerShell@2
    displayName: Set ApplicationDisplayVersion and ApplicationVersion
    inputs:
      targetType: 'inline'
      script: |
          $xml = [Xml] (Get-Content ${{ parameters.SrcFolderName }}\${{ parameters.ProjectFolderName }}\My.App.csproj)
          $xml.Project.PropertyGroup.ApplicationDisplayVersion = "$(App_BUILD_NUMBER)"
          $xml.Project.PropertyGroup.ApplicationVersion = "$(Azure_DevOps_BUILD_ID)"
          $xml.Save("${{ parameters.SrcFolderName }}\${{ parameters.ProjectFolderName }}\My.App.csproj")
    

    And now, in the AppCenter everything is correct: correct version in appcenter