MSIX packaged apps can implement auto update feature really easy
Just checking 'Enable automatic updates' on create app packages wizard.
And there are a few customize points the automatic updates feature such as:
Please see the following document to checking all options:
Configure update settings in the App Installer file
In latest Visual Studio 2019, there is an App Installer item template to configure it.
You can configure it like below:
The above configuration is best configuration to update silently to latest update as far as possible.
Even if there was an update between the background updates every 8 hours, then the app will check update when launching time, and then show confirm dialog for updating.
If you would like to check updates any timing you want, then it can do using Package.CheckUpdateAvailabilityAsync method. After the method is called, when the next launching, if there is an update, then the app will be updated.
In case of setting ShowPrompt option, then progress Window will appear, but confirm dialog will not be displayed. In case of not setting ShowPrompt option, then the app will be updated silently.
For example, if you would like to check updates when users log into Windows, then you can use startup task to call the method. If you don't need any user interface, then you can use following code as startup task.
using System;
using System.Threading.Tasks;
using Windows.ApplicationModel;
namespace AutoUpdateTask
{
class Program
{
static async Task Main(string[] args)
{
await Package.Current.CheckUpdateAvailabilityAsync();
}
}
}
To not see command prompt window, the console app project file's output type is set to WinExe like following:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifiers>win-x86;win-x64</RuntimeIdentifiers>
<Platforms>x86;x64</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.SDK.Contracts" Version="10.0.18362.2005" />
</ItemGroup>
</Project>
And then configure the exe to startup stask, add the definition to Package.appxmanifest, and then startup task registration code to entry point of your main apps:
<desktop:Extension Category="windows.startupTask" Executable="AutoUpdateTask\AutoUpdateTask.exe" EntryPoint="Windows.FullTrustApplication">
<desktop:StartupTask TaskId="AutoUpdateTask" Enabled="true" DisplayName="Auto Update Task" />
</desktop:Extension>
var startupTask = await StartupTask.GetAsync("AutoUpdateTask");
var state = startupTask.State;
if (state != StartupTaskState.Enabled)
{
state = await startupTask.RequestEnableAsync();
}
If the app update was published, then it is checked when users log into Windows, and then the app would be updated automatically.
.appinstaller provides powerful auto update feature, and you can also check updates using Package.CheckUpdateAvairabilityAsync method on any timing you want.
In this article, I explained how to add checking update feature as startup task. If you would like to provide updates to users without UI interaction, then it is good approach for now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.