0

I am attempting to build a Github Action that will publish my .Net Maui app (among other things). So far, I'm only targeting a Windows Desktop deployment of my app.

For context, I've defined the version number of the Windows app's package in the usual way: There's a Package.appxmanifest file within my Windows project that contains a line that looks like this <Identity Name="Myapp" Publisher="..." Version="0.0.58.0" />. Within my code, I retrieve this number using VersionTracking.Default.CurrentVersion. There's other version numbers within the app, such as ApplicationVersion, but I'm not interested in those here.

Within my Github Action, I would like to retrieve this version number and print it to a file. I use dotnet publish to create an MSIX file. I attempted to get the version number with Get-AppxPackage as follows:

        shell: powershell
        run: echo (Get-AppxPackage -Name MyApp).Version > version.txt

This works locally but returns an empty string when run within Github Actions. I assume this is because dotnet publish doesn't actually install the application. I attempted to install within my build script, but I ran into issues related to the certificate associated with the app.

Another approach I've tried is using a pre/post build script to generate this version file during the dotnet publish step. However, I can't find a variable that gives me this version number.

My question is: What is the best way to do this? I can think of three possible routes to go down, but I'm not sure which is the best approach:

  1. Figure out how to build the app on the build server in order to use Get-AppxPackage in the Github Action.
  2. Find a way in the Github Action to retrieve the version number from the MSIX through some other variable.
  3. Find a variable to use with a pre/post build script to do this.

I'm also open to other suggestions. Where is the best place to start for this?

jobrien9
  • 117
  • 3
  • 15
  • 1
    Does this answer your question? [How to fetch an attribute value from xml using powershell?](https://stackoverflow.com/questions/12212452/how-to-fetch-an-attribute-value-from-xml-using-powershell) – Azeem Jun 23 '23 at 04:39
  • 1
    You can simply fetch version directly from the manifest file. Please refer to above thread about how to do that. – Azeem Jun 23 '23 at 04:46
  • 1
    That worked! I can't thank you enough! – jobrien9 Jun 23 '23 at 14:36

1 Answers1

0

Using the link in Azeem's comment, this is what the relevant section of my yml file now looks like:

 # https://stackoverflow.com/questions/76535435/getting-version-number-in-github-actions-for-a-net-maui-app?noredirect=1#comment134947673_76535435
  - name: Create a Version file
    shell: powershell
    run: $appManifest = [xml](Get-Content MyApp/Platforms/Windows/Package.appxmanifest); echo $appManifest.Package.Identity.Version > MyApp/MyOutputFilepath/version.txt

This creates a version.txt file with the version number described in my question above.

jobrien9
  • 117
  • 3
  • 15
  • 1
    Glad you could make it work! You might want to divide that single line into multiple ones for clarity. See the multiline example under [`jobs..steps[*].run`](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun). – Azeem Jun 23 '23 at 15:18