How do I debug a UWP UpdateTask?

In my UWP app, how can I debug the code in my UpdateTask? The Lifecycle Events dropdown in VS 2017 doesn't seem to have a choice to run this type of background task. Is there a way to do this?

+3


source to share


1 answer


First, let's look at some context in the UWP UpdateTask: its a background task that your app can implement to start the system when your UWP gets an update. It runs your code from the updated app package in the background, so you can keep track of any service related to a particular update (such as a data structure change). To customize UpdateTask for your application, you need to do two things:

a) Declare UpdateTask in your appx manifest:

<Extension Category="windows.updateTask" EntryPoint="BackgroundTasks.UpdateTask" />

      

b) Add a Windows Runtime Component that implements the task in a type that matches the EntryPoint declaration and references the component from your application project.

enter image description here

Before debugging the upgrade procedure, first make sure that your original version of the application is deployed. Then change the debug setting in your project properties as follows:

enter image description here



Then, to make sure UpdateTask is running, increase the package version number in the manifest editor:

enter image description here

Now when you hit F5 in VS 2017, your application will be updated and the system will activate the UpdateTask component in the background. The debugger automatically attaches to the background process. Your breakpoint will hit and you will be able to walk through the update code logic (just toast in my example).

enter image description here

When the background task is complete, you can also launch the foreground app from the app list in the same debug session. The debugger automatically attaches again, now to your foreground process, and you can execute your main application logic.

Notes for VS 2015 users: The above applies to VS 2017. If you are using VS 2015, you can use the same methods to run and test UpdateTask, but VS will not attach to it. An alternative procedure in VS 2015 would be to set an ApplicationTrigger , which has the same UpdateTask as the entry point, and triggers execution directly from the foreground.

Thank you Stefan Wick - Windows Developer Platform

+3


source







All Articles