添加 UWP 后台任务导致 AppManifest 错误 [英] Adding UWP Background task causes AppManifest errors

查看:22
本文介绍了添加 UWP 后台任务导致 AppManifest 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试向我的项目添加进程外后台任务以更新我的应用程序的动态磁贴.该任务需要调用数据库来获取一些数据,然后处理该数据以发送一些磁贴通知.

I've been trying to add an out of process background task to my project to update my App's live tile. The task needs to make a database call to get some data, then process that data to send out a few tile notifications.

我已经设法让它在我专门为后台任务功能原型设计的一个项目中工作.但是,当我尝试向主项目添加后台任务时,出现以下错误:

I've managed to get it to work in one project that I created specifically for prototyping the background task functionality. However, when I tried to add a background task to my main project it gives me the following error:

Validation error. error 80080204: App manifest validation error: Line 33, Column 12, Reason: If it is not an audio background task, it is not allowed to have EntryPoint="BackgroundTasks.LiveTileTask" without ActivatableClassId in windows.activatableClass.inProcessServer. 

我搜索了这个错误并找到了一些 post 说我应该添加音频任务类型,错误就会消失,但是我得到了一个不同的错误.我什至没有尝试在后台播放音频,所以我无法理解为什么 UWP 认为我是.

I have searched for this error and found some post which said I should add the audio task type and the error would go away, but then I get a different error. I'm not even trying to play audio in the background, so it's beyond me why UWP thinks I am.

我的项目设置如下所示:

My project setup looks like this:

  • 1 个 UWP 项目,将秋季创作者的更新作为最低/目标版本.
  • 1 个用于数据库的网络标准 2.0 项目(使用 EFcore)

我已尝试遵循 Microsoft 发布的指南,并为后台任务添加一个 WinRT 项目,但这会导致与我的 .net 标准 2.0 项目和 UWP 项目的兼容性问题.我不是一个非常有经验的 UWP 开发人员,所以我想知道是否有人看到了我遗漏的东西.

I've tried following the guidelines published by Microsoft, and add a WinRT project solely for the background task, but that gives compatibility issues all over the place with my .net standard 2.0 project and the UWP project. I'm not a very experienced UWP developer, so I'm wondering if anyone sees something that I'm missing.

让我的后台任务工作的最佳方法是什么?即使应用程序未打开,进程内后台任务是否足以从后台更新动态磁贴?

What would be the best approach to getting my background task working? Is an in-process background task sufficient for updating the live tile from the background, even if the app is not opened?

我使用的是最新版本的 VS 2017 (15.7.1)

I'm using the latest version of VS 2017 (15.7.1)

推荐答案

我遇到了同样的问题.不幸的是,添加音频不是解决方案,因为这将是 Windows 商店的要求,不是一个好主意.设置最低目标版本会给你非常有限的 Windows 应用商店功能和较少的 UWP 功能.

I hit the same issue. Unfortunately adding audio is not a solution as this will be a requirement for the windows store, not a good idea. Setting minimum target version gives you very limited Windows Store functionality and less UWP features.

开始使用此链接并非常小心地遵循它:

Get started by using this link and follow it very carefully:

https://docs.microsoft.com/en-us/windows/uwp/launch-resume/create-and-register-a-background-task

总结:

  • 确保你有一个好的项目副本,我的清单文件在实验过程中损坏了,我需要 Package.appxmanifest 备份副本.
  • 从项目中删除与后台任务相关的所有引用和代码.
  • 在您的解决方案中创建一个新的 Windows Universal/Windows Runtime组件项目.
  • 将项目命名为 BackgroundTasks(例如)
  • 右键单击引用并管理 Nuget 包
  • 选择已安装的选项卡和 Microsoft.NETCore.UniversalWindowsPlatform
  • 将版本从 6.1.4 更改为 6.0.8(6.1.4 似乎是一个预览版本,这会导致每次加载 VS 时都会添加额外的不需要的引用).
  • 将 Class1.cs 名称更改为 MyBackgroundTask.cs
  • 选择 BackgroundTasks 项目 Target/Min version to Fall Creators Update
  • 右键单击您的解决方案/项目依赖项.选择BackgroundTasks并检查构建顺序是否正确,我的设置为BackgroundTasks在主项目之前构建.
  • 请参阅UWP 示例中的示例代码创建示例后台任务.
  • 按照上述链接中的说明更改 Package.appxmanifest 文件.
  • 构建解决方案,您就可以开展业务了.
  • Ensure you have a good copy of your project, my manifiest file became corrupted during experimentation and I needed the Package.appxmanifest backup copy.
  • Delete all references and code relating to anything to do with background tasks from your project.
  • In your solution create a new Windows Universal / Windows Runtime Component project.
  • Name the project BackgroundTasks (as an example)
  • Right click references and Manage Nuget Packages
  • Select the installed tab and Microsoft.NETCore.UniversalWindowsPlatform
  • Change the version from 6.1.4 to 6.0.8 (6.1.4 seems to be a preview version which causes extra unwanted references to be added everytime VS is loaded).
  • Change Class1.cs name to MyBackgroundTask.cs
  • Select the BackgroundTasks project Target / Min version to Fall Creators Update
  • Right click your solution / Project Dependancies. Select BackgroundTasks and check the build order is correct, mine is set for BackgroundTasks to build before the main project.
  • Refer to the sample code at UWP Samples to create the sample background task.
  • Change the Package.appxmanifest file as described on the above link.
  • Build the solution and you should be in business.

我个人建议使用进程外后台任务来消除任何可能,如果后台任务崩溃它不会影响应用程序运行,也更灵活.

Personally I recommend to use an out-of-process background task to eliminate any possibly that if the background task crashes it does not affect the app from running, also much more flexible.

作为提示,您的 BackgroundTaskBuilder 将作为字符串引用:

As a tip your BackgroundTaskBuilder will reference as strings:

 builder.Name = "MyBackgroundTask";
 builder.TaskEntryPoint = "BackgroundTasks.MyBackgroundTask";

我发现在 UWP 中制作后台任务很乏味,但一旦完成就值得付出努力.

I find making background tasks in UWP quite tedious, but once done well worth the effort.

这篇关于添加 UWP 后台任务导致 AppManifest 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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