IBackgroundTask 中的 FullTrustProcessLauncher 不工作

FullTrustProcessLauncher in IBackgroundTask not working

我正在尝试从我的后台任务启动 FullTrustProcess。为此,我正在调用 await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();,但它告诉我 FullTrustProcessLauncher does not exist in this context。我尝试添加 Windows Desktop Extensions for the UWPWindows.ApplicationModel.FullTrustAppContract 对我的后台任务的引用,但随后我无法编译它以供发布(除非我禁用 .Net 本机工具链)。然后我得到的错误是:Internal compiler error: An item with the same key has already been added.

我该如何解决这个问题?我的后台任务需要以某种方式启动 WPF 组件。是否有解决方法,例如在没有 window 的情况下启动 UWP 前台应用程序?还是我 import/permission 错了?请注意,我似乎只需要添加一个引用,但两者都不起作用。

您只需要将其添加为对实现后台任务的项目的引用:

然后您将在 Windows.ApplicationModel 命名空间中找到 FullTrustProcessLauncher API。还要确保组件是 "Windows Runtime Component",而不是 "Class Library"。如果这不起作用,请共享一个演示问题的重现项目。它在我的项目中对我有用。