uwpazure-pipelinesversioningmsixappxmanifest

How can I auto-increment the package version number for a .msixupload file created in an Azure Pipeline?


I am using an Azure Pipeline that runs automatically when I make a commit to my GitHub repository. The .yml file generates a .msixupload file (for UWP) for upload to the Microsoft Store. However, I cannot upload the generated .msixupload file, as the version number in the .appxmanifest file never changes, and I am attempting to build an update for an existing app. How can I increment the version number each time the Azure Pipeline is run?

I have tried adding

<AppxAutoIncrementPackageRevision>True</AppxAutoIncrementPackageRevision>

to the .appxmanifest file as described here: How do I auto increment the package version number?, but that has not made any difference.


Solution

  • You can use powershell scripts to change the version value in appxmanifest file. See below example:

    In your yaml pipeline. You can set variables like below: See here for more information about counter expression.

    variables:
      major: 1
      minor: 0
      build: $(Build.BuildId)
      version:  $[counter(variables['major'], 0)]  
    

    Then add powershell task to run below script to update the version value:

      - powershell: |
           [Reflection.Assembly]::LoadWithPartialName("System.Xml.Linq")
           $path = "Msix/Package.appxmanifest"
           $doc = [System.Xml.Linq.XDocument]::Load($path)
           $xName =
             [System.Xml.Linq.XName]
               "{http://schemas.microsoft.com/appx/manifest/foundation/windows10}Identity"
           $doc.Root.Element($xName).Attribute("Version").Value =
             "$(major).$(minor).$(build).$(revision)";
           $doc.Save($path)
          displayName: 'Version Package Manifest'
    

    Please check this document for more information.

    Since appxmanifest file is just text-based XML file. You can also use Extension tool Magic Chunks task to change version value in appxmanifest file . Check this thread for example.