xamarin.formsmsbuildazure-devops-hosted-agent

Use of XmlPoke in project file to update source file has stopped working [title updated]


For several years to update the version number during project build. In Visual Studio we added something like the following in a c sharp project


  <Target Name="BeforeBuild" Condition=" $(SetVersion) == true ">
    <PropertyGroup>
      <IOSBundleVersion>$([System.Text.RegularExpressions.Regex]::Match($(VersionNumber), '[^.][^.]*.[^.]*.[^.]*'))</IOSBundleVersion>
    </PropertyGroup>
    <XmlPoke XmlInputPath="Info.plist" Query="//dict/key[. = 'CFBundleVersion']/following-sibling::string[1]" Value="$(VersionNumber)" />
    <XmlPoke XmlInputPath="Info.plist" Query="//dict/key[. = 'CFBundleShortVersionString']/following-sibling::string[1]" Value="$(IOSBundleVersion)" />
  </Target>

This should update the file containing a version number which is then used as the application version during the subsequent build.

What actually happens is that the source file is updated but msbuild uses the original file rather than the updated file.

I speculate that msbuild has been changed to load all project files into memory as the first step so will now ignore any changes to files on disk.

Microsoft (R) Build Engine version 16.11.1+3e40a09f8 for .NET Framework exhibits this behaviour

Last worked ok msbuild 15.0

[This was the original post - please ignore]: We are building Xamarin.Forms iOS app and have been for some time. We control the version number in Azure Devops build step 'Xamarin.iOS' via an argument /p:SetVersion=true /p:VersionNumber=$(Application.Version) The info.plist part of the project sets a baseline version (4.00.00.00) The Application.Version parameter is being set (Application.Version == 4.00.00.03) and logs show this is being used. However, the 'Apple App Store Release' reports ERROR ITMS-90189: "Redundant Binary Upload. You've already uploaded a build with build number '4.0.0.0' for version number '4.0.0'. I have manually checked the version of the .ipa artifact built by uploading via iOS Transporter app . This shows that the .ipa has the baseline version , not the value passed to SetVersion.

This started happening when we recently upgraded the hosted agent from Pool: Azure Pipelines Image: macOS-10.15 Agent: Hosted Agent to Image: macOS-11

Has anyone else seen this issue?


Solution

  • Solution is to avoid changing any source files during a msbuild. Instead use a pre-build task to make any source changes e.g. to set a version number.