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:
- Figure out how to build the app on the build server in order to use Get-AppxPackage in the Github Action.
- Find a way in the Github Action to retrieve the version number from the MSIX through some other variable.
- 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?