如何从 Qt 生成带有应用程序清单的 Visual Studio 项目?

How to generate a Visual Studio project with app manifest from Qt?

我能够从 Qt 生成 MSVC 项目 (.vcxproj),但该项目不包含应用程序清单文件 (Package.appxmanifest)。我尝试使用 qmake 变量 WINRT_MANIFEST 并确保 CONFIG 包含 embed_manifest_exe 但我一定是误解了什么。

我的问题分为两部分:

  1. 如何在我的 Qt 项目中定义应用程序清单?
  2. 这个应用程序清单如何成为 Qt Creator / qmake 生成的 MSVC 项目的一部分?

我正在使用 Qt Creator 4.7.1Qt 5.11.2 MSVC2017 64 位Windows 10 我安装了 Visual Studio 2017 Community

我已经尝试过的

构建 MSCV 项目

基于Qt for WinRT documentation和Qt社区的帮助,我运行如下(通过QMAKE_POST_LINK,在我的.pro中设置):

windeployqt --release --compiler-runtime --qmldir path-to-my-qml-files
qmake -tp vc path-to-my-.pro -o path-to-build-folder/target-name.vcxproj CONFIG+=release

这些成功创建了一个 MSVC 项目,发布文件夹包含部署所需的所有库和一个 vcredist_xxx.exe。

正在阅读有关 Windows 应用程序清单的 Qt 文档

Qt documentation for Windows deployment > Manifest files:

When deploying an application compiled with Visual Studio, there are some additional steps to be taken. First, we need to copy the manifest file created when linking the application. ... Since Qt 4.1.3, the following CONFIG options are available for embedding manifests: embed_manifest_dll embed_manifest_exe Both options are enabled by default.

因此,根据我的理解,如果启用了 CONFIG 选项 embed_manifest_exe(默认情况下),那么当 qmake 为 运行.

时应该嵌入清单

Qt documentation for Qmake variables > WINRT_MANIFEST:

Specifies parameters to be passed to the application manifest.

列出了这些,其中许多都有默认值。

那么为什么没有生成应用程序清单?即使我自己没有指定任何内容,WINRT_MANIFESTCONFIG contains embed_manifest_exe 的组合肯定意味着应该嵌入默认清单。

我也尝试设置 WINRT_MANIFEST 属性(例如 WINRT_MANIFEST.publisher),我尝试创建自己的 Manifest.xml 并设置 WINRT_MANIFEST=Manifest.xml. 但这没有区别。

解决方案非常简单 "obvious" 但由于文档中没有提及,我没有意识到它的存在。

问题出在这里:

I am using Qt Creator 4.7.1, Qt 5.11.2 MSVC2017 64bit, on Windows 10 and I have Visual Studio 2017 Community installed.

应用清单由通用 Windows 平台 (UWP) 应用使用,这些应用使用 WinRT(例如 Windows 商店应用)。 Qt 有一套不同的构建工具包用于这些。例如 UWP 32 位的 Qt 5.11.2 (MSVC 2017)。这些使用 mkspecs 开始 winrt- 并在维护工具/安装程序中显示为 UWP x86/64 (MSVC 2017).

使用这些套件之一时,使用默认配置设置 embed_manifest_exe,您将获得一个带有默认清单的 Visual Studio 项目。

要覆盖默认值,请在 .pro 中指定属性,例如WINRT_MANIFEST.publisher,或创建一个单独的清单文件并设置 WINRT_MANIFEST=path-to-manifest-file。如果执行后者,假设您的清单文件是一个 XML 文件,其格式与最终 Package.appxmanifest 相同,那么您还需要 WINRT_MANIFEST.CONFIG += verbatim.