How to debug a UWP UpdateTask?

女生的网名这么多〃 提交于 2019-12-03 17:13:21

First some context on UWP's UpdateTask: It’s a background task your app can implement to get triggered by the system when your UWP has received an update. It runs your code from the updated app package in a background process, so you can take care of any maintenance related to the specific update (e.g. change in data structures). To set up an UpdateTask for your app you need to do two things:

a) Declare the UpdateTask in the 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 reference the component from your app project.

Before debugging the update procedure, first make sure your initial version of the app is deployed. Then change the debug setting in your project properties like this:

Next, to make sure the UpdateTask gets triggered, increase the package’s version number in the manifest editor:

Now when you hit F5 in VS 2017 your app will get updated and the system will activate the UpdateTask component in the background. The debugger will automatically attach to the background process. Your breakpoint will get hit and you can step through your update code logic (in my example just a toast).

When the background task has completed, you can now also launch the foreground app from the app list within the same debug session. The debugger will again automatically attach, now to your foreground process and you can step through your main app logic.

Notes for VS 2015 users: The above applies to VS 2017. If you are using VS 2015 you can use the same techniques to trigger and test the UpdateTask, but VS will not attach to it. An alternative procedure in VS 2015 would be to setup an ApplicationTrigger that has the same UpdateTask as Entry Point, and trigger the execution directly from the foreground app.

Thanks, Stefan Wick – Windows Developer Platform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!