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

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

问题描述

我一直在尝试向我的项目添加进程外后台任务,以更新App的实时图块.该任务需要进行数据库调用以获取一些数据,然后处理该数据以发出一些平铺通知.

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. 

我已经搜索了此错误,并发现了一些帖子,其中说:我应该添加音频任务类型,错误将消失,但是随后出现另一个错误.我什至不尝试在后台播放音频,所以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.

我的项目设置如下:

  • 1个UWP项目以秋季/秋季版本为目标,针对秋季创作者的更新.
  • 1个用于数据库的net standard 2.0项目(使用EFcore)

我已经尝试按照Microsoft发布的指南进行操作,并添加了一个仅用于后台任务的WinRT项目,但是这给我的.net standard 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/zh-CN/windows/uwp/launch-resume/create-and-register-a-background-task

总结一下:

  • 确保您的项目具有良好的副本,在实验期间我的manifiedt文件已损坏,并且我需要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版本进行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天全站免登陆