Testing Pre-Install Task on UWP Apps

Microsoft provides an entry point to execute UWP app’s code even before the application is opened by the user. The entry point is available through background task component which can be triggered during deployment task. There are two deployments task types available to UWP: PreInstallConfigTask and UpdateTask.

In this article I will guide you on how to incorporate and test PreInstallConfigTask in your application. Note that PreInstallConfigTask is only available for pre-installed application.

Clone https://github.com/pradithya/UwpSamplePreInstalledApp for the sample code.

I created a background task (Windows Runtime Component) with name BackgroundTask.PreInstalledTask. The background task will only display a toast notification with pre-defined text information.

namespace BackgroundTask
{
    public sealed class PreInstalledTask : IBackgroundTask
    {
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            ToastHelper.PopToast("Pre-Install Task", "Pre install task is running", "OK");
        }
    }
}

Add pre-installed task capability to the main application’s app manifest and hook it to the background task.

preinstall

Now the application is ready and we can test it.
Create application package for testing (see how).
Once the app package is created, open PowerShell as Administrator and enter the following command.

Add-AppxProvisionedPackage -Online -PackagePath [*appx / *appxbundle path] -SkipLicense

This command will use DISM to include the application into current Windows image. In the same time, the deployment of the application for the current user will be done and the pre-install task will also be triggered. In this application context, the task will display toast notification as shown below.

preinstall

As the application become the part of Windows image, every time you create a new user the application will be available as a pre-installed app. To revert this behavior you’ll need to remove all of the application instances in each user and execute following command in Powershell.

Remove-AppxProvisionedPackage -online -packagename TestPreInstalledApp_1.0.0.0_neutral_~_yzekw4x8qxe1g

source:
https://docs.microsoft.com/en-us/windows-hardware/customize/preinstall/preinstall-tasks
https://docs.microsoft.com/en-us/windows/uwp/publish/generate-preinstall-packages-for-oems
https://technet.microsoft.com/library/dn376490(v=wps.620).aspx

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s