Make a Windows app ready for the Microsoft Store

Hi. I’m new to using CMake to prepare an app for the Microsoft Store.

Can you help or direct me to a tutorial that walks through the process?

Background: I’m a Qt developer. I’ve published to the Microsoft Store using Qt’s old qmake build system but not CMake. And I’ve worked out how to publish to the App Store using Qt + CMake, which was not straightforward and involved help from @craig.scott and others.

CMake code:
Qt’s own documentation only goes as far as mentioning that I need to include

set_target_properties(MyApp PROPERTIES
    WIN32_EXECUTABLE ON
)

From my own research, I think that the following should package the AppxManifest.xml and associated assets, ready for the Microsoft Store, in this way… but I’m not sure:

set_property(SOURCE AppxManifest.xml PROPERTY VS_DEPLOYMENT_CONTENT 1)
foreach(asset ${ASSET_FILES})
    set_property(SOURCE "${asset}" PROPERTY VS_DEPLOYMENT_CONTENT 1)
    set_property(SOURCE "${asset}" PROPERTY VS_DEPLOYMENT_LOCATION "Assets")
endforeach()

Help requested:
I would be grateful for help with the following:

  1. Any CMake commands that I ought to be including when prepping for the Microsoft Store.
  2. A tutorial of step by step process from running CMake to uploading the package.
  3. Any Qt-specific idiosyncrasies I should be aware of, or additional steps I should do.

Other useful info about my situation:

  • I already have a Qt app that is complete and runs on Windows.
  • I have already prepared the AppxManifest.xml and assets (icons, splash screen).
  • I believe I need to run Qt’s windeployqt to compile a list of dependencies, so I have added that to my build steps.
  • When I used to build using qmake, I would get this far in Qt Creator and then finish off, packaging & code signing the app, within Visual Studio. I have Visual Studio Community 2022 installed, but I’m unclear whether/how I’ll need to use that now that I’m using CMake.
  • By default Qt Creator uses Ninja, so I’ve been using that.
  • If I need to use Visual Studio, can CMake generate a VS project?
1 Like

It seems there is some kind of support (at least for phones…not sure about the desktop store off-hand). Looking at this test might help show what is missing.

1 Like

Thanks Ben, I’ll check that out. First glance suggests that it includes Windows.Universal apps not just phones / WinRT, although there’s quite a lot of historic code in there.

In theory the CPack WIX Generator should be able to generate MSIX packages required by the Windows Store.

In practice Feature request: Support for Microsoft’s new MSIX installer format · Issue #5781 · wixtoolset/issues (github.com) is still open (since March 2018).

Do I understand correctly that the publishing process worked for you with QMake, because you were able to create a Visual Studio project (using qmake -tp vc) and do the necessary step in VS?

CMake can create VS projects too by choosing a VS project generator: https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html#visual-studio-generators

wpbest/cmake-win-store-app: CMake project of a Windows Store Application (github.com) has a sample CMake project.

The project was made 8 years ago, no idea if this is still working.

Package from the command line - MSIX | Microsoft Learn contains the information about creating MSIX packages.

From skimming it’s all about having some xml (AppManifest.xml) files, a map file, and then two calls to:

  • makeappx.exe
  • SignTool.exe

I assume Visual Studio does all of that behind the scenes.

Yes. I used to have qmake code that included a vs generator (not sure where I found that code) and I could take it from there.

With CMake, I have indeed taken the MSVC2019-64bit kit and changed the generator to “Visual Studio 16 2019”. Although there’s no documentation around this, I also discovered that I had to add

-DCMAKE_SYSTEM_NAME:STRING=WindowsStore
-DCMAKE_SYSTEM_VERSION=10.0

However when I switched over to Visual Studio and built the app and tried running it, it would always fail with “missing dependent DLLs” error.

Despite having added in a windeployqt step (which I didn’t need to explicitly do in qmake), and runnung the vc_redist.exe to ensure the MS DLLs are in place, and running “Dependencies” (the modern dependency walker) to ensure I have all necessary DLLs in place, it still fails with the same error.

As a result, although I can compile and run my app in Qt Creator using the Ninja generator, it won’t work by the above method. To rule out app-specific issues, I used Qt Creator to create a minimal “Hello World” project (new Qt Quick project) and this suffered the same problems.

If you’ve had success using the VS generator, I’d be grateful to know what your process was.

I looked at this and it didn’t help me. As you say, not updated for 8 years. It’s all targeting WINRT (e.g. VS_WINRT_COMPONENT CMake property) and has other things that are Windows 8.1 specific.

I find it weird that there’s (apparently) no repo out there with a CMake for WinUI3 or anything newer than 5 years old.

With CMake, I have indeed taken the MSVC2019-64bit kit and changed the generator to “Visual Studio 16 2019”.

@jobor To be fair to you, I worked this out after having written this post, but I’m still looking for a process to answer my original question.

Right now I’m still trying some manual steps to try and get a solution. I would dearly love something that is automated… that I can configure in CMake within the project and which will generate a runnable, packageable VS project. (This is where I was able to get to with Xcode and the App Store in the end.)

Sorry, I’ve never packaged an app for the Microsoft Store. The problem seems to be rooted in the “missing dependent DLLs” error. You need to make sure that the Qt DLLs are next to the .exe, and the necessary Qt plugins are copied to the correct directory. The windeployqt tool should take care of this.

Maybe you could post a layout of the directory you’re trying to package.

I took a Qt Example for a run Affine Transformations with Visual C++ 2019 x64.

Ran windeployqt.exe on the affine.exe and this is what I’ve got:

[generic]
[iconengines]        
[imageformats]       
[networkinformation] 
[platforms]
[styles]             
[tls]                
[translations]
affine.exe
opengl32sw.dll       
Qt6Core.dll          
Qt6Gui.dll           
Qt6Network.dll       
Qt6OpenGL.dll        
Qt6Pdf.dll
Qt6Svg.dll           
Qt6Widgets.dll       
vc_redist.x64.exe

Then I looked at the dependencies that affine.exe has:

$ dumpbin /imports affine.exe  | findstr .dll
    Qt6Widgets.dll
    Qt6OpenGL.dll
    Qt6Gui.dll
    Qt6Core.dll
    VCRUNTIME140.dll
    VCRUNTIME140_1.dll
    api-ms-win-crt-heap-l1-1-0.dll
    api-ms-win-crt-runtime-l1-1-0.dll
    api-ms-win-crt-math-l1-1-0.dll
    api-ms-win-crt-stdio-l1-1-0.dll
    api-ms-win-crt-locale-l1-1-0.dll
    SHELL32.dll
    KERNEL32.dll

The C++ runtime DLLs VCRUNTIME140.dll and VCRUNTIME140_1.dll are not deployed by windeployqt. It instead deploys the vc_redist.x64.exe C++ runtime installer, which doesn’t help running the affine.exe executable. affine.exe would require an installer that would install vc_redist.x64.exe before hand. This is what Qt Creator’s installer does.

Windows Store expects an application with ALL the dependencies present, including the usually shared C++ runtime.

If we look at the Deployment in Visual C++ documentation we can see that windeployqt does a Central deployment while a Windows Store application needs a Local deployment.

You can do a manual deployment. I had a look at my <build-dir>/CMakeFiles/3.25.2/CMakeCXXCompiler.cmake to find out which Visual C++ compiler it used:

set(CMAKE_CXX_COMPILER "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe")

Then by swapping Tools with Redist I’ve got:

"C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Redist/MSVC/14.29.30133" 

Which does contain the vc_redist.x64.exe binary that windeployqt picked.

And under

"C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Redist/MSVC/14.29.30133/x64/Microsoft.VC142.CRT"

I’ve got the needed files:

concrt140.dll
msvcp140.dll
msvcp140_1.dll
msvcp140_2.dll
msvcp140_atomic_wait.dll
msvcp140_codecvt_ids.dll
vccorlib140.dll
vcruntime140.dll
vcruntime140_1.dll

Copying the files from here would make a Local deployment of the C++ runtime. Note that all these files are 1.6 MiB in size, while vc_redist.x64.exe is 24 MiB in size.

windeployqt also deploys a file your Qt6 application might not need. The MESA llvmpipe Software OpenGL opengl32sw.dll which is 19.6 MiB in size.

I’ve created [QTBUG-116171] windeployqt allow local deployment of MSVC C++ Runtime - Qt Bug Tracker to track the issue of local deployment of C++ runtime.

Yes I got the same thing… all the Qt6 .dlls in the same folder as the .exe

True that the VC runtimes aren’t installed by windeployqt. However, you can add package dependencies to the Package.appxmanifest and these tell the Microsoft Store to download and install those dependencies for you.

e.g.

  <Dependencies>
    <TargetDeviceFamily Name="Windows.Desktop"
                        MinVersion="10.0.0.0"
                        MaxVersionTested="10.0.0.0" />
    <PackageDependency Name="Microsoft.VCLibs.140.00" MinVersion="14.0.24217.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" />
    <PackageDependency Name="Microsoft.VCLibs.140.00.UWPDesktop" MinVersion="14.0.24217.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" />
  </Dependencies>

I found that my app needed a combination of files like VCRUNTIME140.dll and VCRUNTIME140_APP.dll. From what I could tell, the _APP might correspond to the .UWPDesktop suffix but I’m unsure. I also don’t know if you could/should have 2 such package dependencies.

However this didn’t help me with running my app locally. Maybe this is where my “missing DLL” issue comes from. I tried running the vc_redist.x64.exe locally which did install but didn’t help my app run locally.

This is where I’m stuck.

The runtime can be handled with the InstallRequiredSystemLibraries cmake module.

1 Like

It occurs to me that Krita is on the Windows Store and is built with CMake. I expect its Windows Store code is somewhere in its repository: Graphics / Krita · GitLab

I’ve pushed cristianadam/AffineWindowsStore: The Affine Transformations Qt Widgets Example with Windows Store deployment (github.com)

I took the details from the Kate’s installed AppManifest.xml and was able to create an appx package that was installed on my system.

In the end it was just calling makeappx and signtool executables. The crux was mostly to get the right values in the AppManifest.xml and this can be part of cpack-generators(7) — CMake 3.27.3 Documentation

1 Like

CPack: Add support for MSIX/Appx (#18214) · Issues · CMake / CMake · GitLab (kitware.com)

Should be as simple as generating a manifest with the install files and then invoking MakeAppx on windows.

:wink:

Update:
With help from @cristianadam and some others (Qt Discord + Qt bug support team), I can now get an app deployed via the Microsoft Store (as a beta, aka package flight) which is a significant forward step.

However there is a blocking issue that prevents it being published. I’ve created a new forum thread specifically for that. Your ideas would be very much welcomed.