如何调试 UWP UpdateTask? [英] How to debug a UWP UpdateTask?

查看:19
本文介绍了如何调试 UWP UpdateTask?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 UWP 应用中,如何通过 UpdateTask 中的代码进行调试?VS 2017 中的生命周期事件"下拉菜单似乎没有提供触发此类后台任务的选项.有没有办法做到这一点?

In my UWP app, how can I debug through the code in my UpdateTask? The ‘Lifecycle Events’ dropdown in VS 2017 doesn’t seem to offer a choice to trigger this type of background task. Is there a way to accomplish this?

推荐答案

首先是关于 UWP 的 UpdateTask 的一些上下文:它是您的应用可以实现的后台任务,以便在您的 UWP 收到更新时由系统触发.它在后台进程中从更新的应用程序包中运行您的代码,因此您可以处理与特定更新相关的任何维护(例如数据结构的更改).要为您的应用设置 UpdateTask,您需要做两件事:

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) 在 appx 清单中声明 UpdateTask:

a) Declare the UpdateTask in the appx manifest:

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

b) 添加一个 Windows 运行时组件,该组件以与 EntryPoint 声明匹配的类型实现任务,并从您的应用项目中引用该组件.

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:

接下来,为了确保 UpdateTask 被触发,在清单编辑器中增加包的版本号:

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

现在,当您在 VS 2017 中按 F5 时,您的应用将得到更新,系统将在后台激活 UpdateTask 组件.调试器将自动附加到后台进程.您的断点将被命中,您可以逐步执行更新代码逻辑(在我的示例中只是祝酒词).

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.

VS 2015 用户注意事项:以上适用于 VS 2017.如果您使用的是 VS 2015,您可以使用相同的技术来触发和测试 UpdateTask,但 VS 不会附加到它.VS 2015 中的另一种方法是设置 ApplicationTrigger 与 Entry Point 具有相同的 UpdateTask,并直接从前台应用触发执行.

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.

谢谢,Stefan Wick – Windows 开发者平台

Thanks, Stefan Wick – Windows Developer Platform

这篇关于如何调试 UWP UpdateTask?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆