Recently we wanted to enable auto-updates for an app that we were developing for a client. The app is developed in UWP and it's sideloaded into the client's computers. Although Microsoft has added an auto-update functionality in the 1803
build of Windows, we had a few issues with it:
- It was not very reliable
- We didn't have much control over it beside a simple auto-update policy that specified how often it should check for updates.
- Troubleshooting was very hard as there were no clear way to find out why the auto-updater was not working properly.
So I found an article from 2016 and decided to improve upon it and put it a nuget package. The library is open-source and is available on GitHub.
How to use
- First, configure the IIS server and create a web app. You can also take a look at the sample web app.
- Install the nuget package:
Dwrandaz.AutoUpdateComponent
in the UWP app. - Set minimum version of the app to
1803
- Open the package manifest
.appmanifest
file of the main app and declare an app service:- Name: The default values is
Dwrandaz.AutoUpdate
. However, you can change it to any name you like but you should note that this name is important and it should be passed toAutoUpdateManager.TryToUpdateAsync
if you don't use the default name. - Entry point:
Dwrandaz.AutoUpdateComponent.UpdateTask
- Name: The default values is
- Right click on the package manifest
.appmanifest
file and click onView Code
. - Add this namespace declaration:
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
- Add
rescap
to theIgnorableNamespaces
, for example:IgnorableNamespaces="uap mp rescap"
- Inside the
Package
tag, make sure these elements exist:
<Capabilities>
<Capability Name="internetClient" />
<rescap:Capability Name="packageManagement" />
</Capabilities>
For more information, take a look at the sample apps manifest file.
- Example usage:
var path = "http://localhost:5000/install/AwesomeApp.appinstaller";
var info = await AutoUpdateManager.CheckForUpdatesAsync(path);
if (!info.Succeeded)
{
// There was an error in getting the update information from the server
// use info.ErrorMessage to get the error message
return;
}
if (!info.ShouldUpdate)
{
// The app is already up-to-date :)
return;
}
// You can use info.MainBundleVersion to get the update version
var result = await AutoUpdateManager.TryToUpdateAsync(info);
if (!result.Succeeded)
{
// There was an error in updating the app
// use result.ErrorMessage to get the error message
return;
}
// Success! The app was updated, it will restart soon!
For more infromation take a look at the Sample app.
Creating update packages
- Make sure you select the
Release
configuration - Right click on the main app project and click
Store
>Create App Packages...
- Select
I want to create packages for sideloading.
And check theEnable automatic updates
checkbox - Click on
Next
- Check the
Automatically Incremenent
checkbox underversion
. - Select
Always
underGenerate App bundle
- Click on
Next
- Write the update location path and Select
Check every 1 Week
or more so that the native auto-update mechanism doesn't mess with our auto-update mechanism. - Click on
Create
- Upload the
.appinstaller
,.index.html
and the package folder to the web app in the path that was used inAutoUpdateManager.CheckForUpdatesAsync
.
Top comments (2)
Hi Muhammad, first off great article and thank you for packaging this into a NuGet package. I'm going to take a look at this tonight as we're facing similar issues with the auto-updater from 1803.
Quick question, did you manage to test this out in Assigned Access (Kiosk) mode?
I have not tested it myself, but someone else did. The app would crash in Assigned Access mode if the app checked for updates at startup, they found out that introducing a little bit of delay fixed the problem.