Alexander Trauzzi
Alexander Trauzzi

Reputation: 7396

How can I automate supplying a version in appxmanifest?

I am using the desktop bridge for a WPF desktop application and am looking to automate the creation of my msix packages during build. I do not want to store any version information in source control.

The WPF project in the solution uses the gitversion msbuild task to automatically infer the version for my executable every time a build is done. Unfortunately, I'm not sure if any such similar mechanism exists for .appxmanifest.

My thinking is that it would be nice to have this nicely integrated with the build process, similar to gitversion, but I haven't been able to find any documentation about what my options are during build or the Create App Packages process.

Perhaps there's some transform step during build that I'm not aware of that can be done to the .appxmanifest? Or maybe there's a way to have the version always reflect the version of the executable being bundled?

(MSDN forums question)

Upvotes: 7

Views: 2179

Answers (3)

clfaster
clfaster

Reputation: 1824

Here is an Example for Github Workflow as well, I've set the new version in my repository variables in vars.VERSION beforehand.

    - name: Update Version in manifest
      working-directory: './pathToFile/eg/Windows'
      run: |
        $xmlFilePath = "Package.appxmanifest"
        [xml]$xml = Get-Content $xmlFilePath
        $newVersion = "${{ vars.VERSION }}"
        $xml.Package.Identity.Version = $newVersion
        $xml.Save($xmlFilePath)
        Write-Output "Version updated to $newVersion in $xmlFilePath"

Upvotes: 0

mm8
mm8

Reputation: 169150

Your should modify the .appxmanifest file in your build pipeline before you create the package. After all, it's just a text-based XML file.

If you are using Azure Pipelines, you could accomsplish this using a Powershell task and a counter variable that gets incremented for each build:

    pool: 
      vmImage: vs2017-win2016
    variables:
      buildPlatform: 'x86'
      buildConfiguration: 'release'
      major: 1
      minor: 0
      build: 0
      revision: $[counter('rev', 0)]
    steps:
    - 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'
    +Build, Package and Sign.

Please refer to this MSDN Magazine article for more information and a complete example of how to set up continuous integration (CI), continuous deployment (CD) and automatic updates of sideloaded MSIX packaged WPF applications using Azure Pipelines.

Upvotes: 6

rido
rido

Reputation: 1242

You must update the manifest before packaging. Check out this sample including a powershell script to poke the xml with the gitversion provided. https://github.com/microsoft/devops-for-windows-apps/blob/master/azure-pipelines.yml#L72

Upvotes: 2

Related Questions