Automatic version numbering for iOS Xamarin project in Azure Pipelines


For my project (Mobile iOS application, based on Xamarin) I have set up Azure Pipelines build process.
I would like to automatically increase and set the ipa-file version for every build.

Upon searching the Internet I have found an article that advises to add the following code to the ios project .csproj file:

<Target Name="BeforeBuild" Condition=" $(SetVersion) == true ">
    <GetAssemblyIdentity AssemblyFiles="$(AssemblyPath)">
        <Output TaskParameter="Assemblies" ItemName="AssemblyInfo" />
        <VersionNumber>$([System.Text.RegularExpressions.Regex]::Match(%(AssemblyInfo.Version), `[^.][^.]*.[^.]*.[^.]*`))</VersionNumber>
    <XmlPoke XmlInputPath="Resources/Info.plist" Query="//dict/key[. = 'CFBundleVersion']/following-sibling::string[1]" Value="$(BuildNumber)" />
    <XmlPoke XmlInputPath="Resources/Info.plist" Query="//dict/key[. = 'CFBundleShortVersionString']/following-sibling::string[1]" Value="$(VersionNumber)" />

I set version number manually and as I don’t need the assembly version number I have added this simplified code to my iosProject.csproj file:

  <Target Name="BeforeBuild" Condition=" $(SetVersion) == true ">
        <XmlPoke XmlInputPath="Info.plist" Query="//dict/key[. = 'CFBundleVersion']/following-sibling::string[1]" Value="$(BuildNumber)" />
        <XmlPoke XmlInputPath="Info.plist" Query="//dict/key[. = 'CFBundleShortVersionString']/following-sibling::string[1]" Value="$(VersionNumber).$(BuildNumber)" />

In my azure-pipelines.yml file I have the following command line with hardcoded values (just for debugging purposes) for msbuild call:

    mobileProjectMSbuildArgumentsForIOS: "/p:SetVersion=true /p:VersionNumber=1.0 /p:BuildNumber=34 /bl:$(Build.ArtifactStagingDirectory)/build_iOS.binlog"

As you can see, SetVersion is true, VersionNumber is 1.0 and BuildNumber is 44.

Tasks to make the build and generate binary log are as follows:

  - task: [email protected]
      solutionFile: '**/*iOS.csproj'
      signingProvisioningProfileID: '$(APPLE_PROV_PROFILE_UUID)'          
      configuration: '$(buildConfiguration)'
      msbuildArguments: "$(mobileProjectMSbuildArgumentsForIOS)"
      outputDirectory: "$(outputDirectory)"
      packageApp: true
      args: /p:IpaPackageDir="$(outputDirectory)"

  - task: [email protected]
    displayName: 'Publish binary log'
      PathtoPublish: '$(Build.ArtifactStagingDirectory)'
      ArtifactName: 'Binary log'
      publishLocation: 'Container'
    condition: succeededOrFailed()

But when the project has been built using pipelines, the build is green, but:

  1. The version of the ipa-file has not set to the expected 1.0.34, it has old value, that was set manually in .plist file in the project.

  2. binary log is not being generated. upon running task to publish the binary log I get the message:

##[warning]Directory ‘/Users/runner/work/1/a’ is empty. Nothing will be added to build artifact ‘Binary log’.

My questions:

Why XmlPoke does not work for ios.csproj file, even SetVersion is set to true?

Why binary log is not being generated?

Any ideas are welcome.

Thank you.

Source: Xamarin.ios Questions

Categorised as Uncategorised Tagged , ,


Leave a Reply

Your email address will not be published. Required fields are marked *

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us