Search code examples
windowsqtmanifestqmakeappxmanifest

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


I am able to generate an MSVC project (.vcxproj) from Qt but the project doesn't contain an app manifest file (Package.appxmanifest). I have tried using the qmake variable WINRT_MANIFEST and making sure that CONFIG includes embed_manifest_exe but I must be misunderstanding something.

My question has 2 parts:

  1. How can I define an app manifest within my Qt project?
  2. How can this app manifest become part of the MSVC project generated by Qt Creator / qmake?

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.

What I've tried already

Building an MSCV project

Based on the Qt for WinRT documentation and help from the Qt community, I run the following (via QMAKE_POST_LINK, set in my .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

These successfully create an MSVC project and the release folder contains all the libraries needed for deployment and a vcredist_xxx.exe.

Reading Qt documentation on Windows app manifest

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.

So, by my understanding, if CONFIG option embed_manifest_exe is enabled, which it is by default, then the manifest should be embedded when qmake is run.

Qt documentation for Qmake variables > WINRT_MANIFEST:

Specifies parameters to be passed to the application manifest.

These are listed, many of which have defaults.

So why is it that an app manifest isn't being generated? Even if I don't specify anything myself, surely the combination of WINRT_MANIFEST and CONFIG contains embed_manifest_exe should mean that a default manifest should be embedded.

I have also tried setting WINRT_MANIFEST properties (e.g. WINRT_MANIFEST.publisher) and I have tried creating my own Manifest.xml and setting WINRT_MANIFEST=Manifest.xml. But this makes no difference.


Solution

  • The solution is very simple and "obvious" but as it not mentioned in the documentation I had not realised it existed.

    The problem is here:

    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.

    The app manifest is used by Universal Windows Platform (UWP) apps, which make use of WinRT (e.g. Windows Store apps). Qt has a different set of build kits for these. For example Qt 5.11.2 for UWP 32 bit (MSVC 2017). These use the mkspecs starting winrt- and appear in the Maintenance Tool / installer as UWP x86/64 (MSVC 2017).

    When using one of these kits, with the default CONFIG setting embed_manifest_exe, you will get a Visual Studio project with the default manifest.

    To override the defaults, either specify attributes in the .pro, e.g. WINRT_MANIFEST.publisher, or create a separate manifest file and set WINRT_MANIFEST=path-to-manifest-file. If doing the latter, assuming your manifest file is an XML file of the same form as the final Package.appxmanifest, then you also need WINRT_MANIFEST.CONFIG += verbatim.