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:
I'm also open to other suggestions. Where is the best place to start for this?
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.