How to Set Automatic MSIX Downgrades with .appinstaller
As we've emphasized before, we're big fans of MSIX technology here at Advanced Installer. It has brought more control to developers when it comes to their packages -- as it includes options for repackaging, rolling back updates and even downgrade scenarios.
In a previous article, we had a look on how to enable auto-updates in MSIX without using the Microsoft Store -- and we also have a video on the topic that you can check below:
When enabling auto-updates, we used the .appinstaller file, which you can use to specify where your app is located and how to update it.
In the .appinstaller file, you also have the ForceUpdateFromAnyVersion element. If this element is set as true, it will allow your application to automatically update to a higher version -- and, in addition, it will also automatically enable the downgrade to a previous version.
Without it, the app can only upgrade to a higher version.
Let’s have a look at some scenarios on how this ForceUpdateFromAnyVersion element actually works and how to handle MSIX downgrades with the .appinstaller file.
How to create the .appinstaller file to enable MSIX downgrades
Advanced Installer offers the possibility to quickly create the .appinstaller file directly from its GUI.
To create the .appinstaller file, follow the steps below:
1. Navigate to Builds in your project.
2. Click on your MSIX build (Build_MSIX_APPX).
3. Click on the App Installer tab.
4. Paste the URL where your .appinstaller and MSIX will be located. In this scenario, we are using a local share. Here's where you must specify your own URL.
5. Specify the desired Frequency check. In this case, we went with 0 which means that every time the application is started, it will check on our server to see if an update is available.
6. Check the Force update from any version.
7. Click Build in the upper left corner.
The outputted .appinstaller file should look something like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <AppInstaller Uri="file://\\storage\temp\MyApp\Startup Application Example-x64.appinstaller" Version="188.8.131.52" xmlns="http://schemas.microsoft.com/appx/appinstaller/2018"> <MainPackage Name="Caphyon.StartupApplicationExample" Version="184.108.40.206" Publisher="CN=TestCert_2020-3-25_14-56-53" Uri="file://\\storage\temp\MyApp\Startup Application Example-x64.msix" ProcessorArchitecture="x64"/> <UpdateSettings> <OnLaunch HoursBetweenUpdateChecks="0"/> <ForceUpdateFromAnyVersion>true</ForceUpdateFromAnyVersion> </UpdateSettings> </AppInstaller>
As you can see, the ForceUpdateFromAnyVersion element is set as true, which means that technically, we can downgrade the application if we choose to.
Testing MSIX downgrade scenarios
There are two scenarios we should consider when testing downgrades:
The user installed the higher version MSIX directly.
In the first scenario, we install version 220.127.116.11 of our application with the .appinstaller file from the previously mentioned local share.
Once version 18.104.22.168 is installed, let’s try to downgrade it to version 22.214.171.124 of the application. To do this, all we did was add the 126.96.36.199 version of the MSIX and the .appinstaller file to the same share. Then, we launched the installation via the .appinstaller file.
The .appinstaller file must specifically mention the version of the application (in our case, 188.8.131.52), and the MSIX besides it must match that version.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <AppInstaller Uri="file://\\storage\temp\MyApp\Startup Application Example-x64.appinstaller" Version="184.108.40.206" xmlns="http://schemas.microsoft.com/appx/appinstaller/2018"> <MainPackage Name="Caphyon.StartupApplicationExample" Version="220.127.116.11" Publisher="CN=TestCert_2020-3-25_14-56-53" Uri="file://\\storage\temp\MyApp\Startup Application Example-x64.msix" ProcessorArchitecture="x64"/> <UpdateSettings> <OnLaunch HoursBetweenUpdateChecks="0"/> <ForceUpdateFromAnyVersion>true</ForceUpdateFromAnyVersion> </UpdateSettings> </AppInstaller>
Upon launching the installation of version 18.104.22.168, the .appinstaller will recognize that version 22.214.171.124 is present on the machine. Now, if we want to "force downgrade it", we have to click Update.
After clicking Update, if we go to Add/Remove Programs, we will see that our app has been downgraded to 126.96.36.199 (which means that the ForceUpdateFromAnyVersion element works as intended).
Now that we made sure that the first scenario (when a user installed the higher version MSIX via the .appinstaller) works as intended, we need to figure out the second scenario (when a user installed the higher version of MSIX directly).
We went and installed version 188.8.131.52 MSIX directly from the share, without using the .appinstaller file. Then, we tried installing the version 184.108.40.206 from the share using the .appinstaller file.
After following those steps, we got the same Update window that we received in the first scenario, confirming that the downgrade also works in the second scenario.
What if we downgrade through MSIX?
As you saw, we manually downgraded the application in both scenarios using the .appinstaller file, but there are a few things to keep in mind when handling downgrades in MSIX.
For instance, what if we use MSIX directly?
If a user installs a higher version of the application using MSIX directly (even if you put an .appinstaller file and an older version of the application on the same share), the MSIX installed on the user machine will not automatically downgrade.
The MSIX installed on the user machine does not know that it has to check on a share for updates, what interval it has to check for updates, how to install the updates, etc. All of those options are specifically defined in the .appinstaller file, and the MSIX does not read from the .appinstaller file during installation.
So, you have to take in consideration all the above factors when you choose the means to provide your packages to the user from the start, otherwise you might find it difficult to handle these scenarios.
Just as a short note, if you ever want to downgrade an MSIX package, you can also do it in MSIX without using the .appinstaller file, it just won’t be automated.
For example, if version 220.127.116.11 of the MSIX is installed on the machine, when you try to install version 18.104.22.168, the following screen will appear:
If you click Reinstall, it will ask if you want to downgrade:
In conclusion, using an .appinstaller file can downgrade an installation performed either through MSIX, or a previous .appinstaller file. Just remember, if you want to allow an automatic downgrade of the application, make sure to always instruct the users to install the application using the .appinstaller file.
You can also perform the downgrade manually in the MSIX file.
Learn more about MSIX downgrades by checking out our video about it here:
I hope this article was helpful, let us know if you have questions or comments!