Microsoft

MSIX packaged apps can implement auto update feature really easy

Just checking 'Enable automatic updates' on create app packages wizard.

KazukiOta_0-1587693341707.png

And there are a few customize points the automatic updates feature such as:

  • ShowPrompt attribute for OnLaunch element: A boolean taht if UI will be shown to the user, when update is available on start up time of the app. 
  • UpdateBlocksActivation for OnLaunch element: A boolean that determines if the UI shown to the user allows the user to launch the app without taking the update.
  • AutomaticBackgroundTask element: Checks for updates in the background every 8 hours independntly of whether the user launched the app. This type of update cannnot show UI.

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.

KazukiOta_0-1587697192793.png

You can configure it like below:

KazukiOta_1-1587697341207.png

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.

Conclusion

.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. 

Comments
Microsoft
www.000webhost.com