Tech Community Live: Windows edition
Jun 05 2024, 07:30 AM - 11:30 AM (PDT)
Microsoft Tech Community

How to package a Windows Desktop C++ application together with its DLL dependency using MSIX

Copper Contributor

Hello,

 

I'm trying to understand how to package a simple Windows desktop application and a custom DLL which are written in C++, using MSIX.

 

The steps I roughly did using latest / updated Visual Studio 2022:

1) Create a solution and project using New project -> Windows Desktop Application C++ / Windows / Desktop

2) Add a new "Dynamic-Link Library" project to the same solution.

3) Add an exported C++ function (via a .h / . cpp pair) into the dll library and use it in the windows desktop application's main function.

4) Add a reference and build dependency to the library in the application project.

5) Build and confirm that everything runs and works as expected. The output directory of the executable also contains the dll.

6) Add a new "Windows Application Packaging Project" to the solution.

7) Add the application as a project reference to the packaging project and set the application as the entry point.

8)Try to build and run the application via the packaging project.

Observe error dialog "app.exe - System Error" "The code execution cannot proceed because mylib.dll was not found".

Indeed if i go into the packaging project build folder (mysolution/MyMSIXProject/bin/x64/Debug/myapp), the executable itself is present (app.exe), its pdb file is present, but the mylib.dll file is missing, although its pdb file is present.

 

If i go to the non-packaging project build dir, i can confirm the existence of both the .exe and the .dll file.

 

I even tried doing some things like adding test.txt files, and marking them as content and changing their Item Type to "Copy file", and i observe that they do get copied into the regular executable output dir, but not to the packaging dir.

 

I also tried creating the msix file by right clicking the packaging project and choosing Publish -> Create App Packages -> sideload, unzipping the msix file and confirming the missing .dll and .txt files.

 

I played with a lot of the project and solution properties, but could not get the .dll and .txt files to be deployed.

 

What am I doing wrong? How can i package / deploy extra .dll and .txt files?

Thank you in advance.

 

Here is my playground solution, in case it is helpful

https://github.com/alcroito/vs_msix_playground

 

sol1 - the solution name

myd1 - the dll library project

wp1 - the windows desktop executable project

MyMSIX - the packaging project

 

2 Replies
With a WAP project, if you just place all the dlls into the root folder of the project, they should be found automatically when running packaged. No need for adding the PSF for that. PS: When running unpackaged, the PSF doesn't work as it has to read container properties.

I'm not sure about your .txt files, but probably using the desktop7 extension to set the working directory would help.

@TIMOTHY MANGAN 

Hello, thank you for your reply.

Could you maybe clarify your answer a bit more? Because I am not very familiar with these projects.

 

How and at what stage should I place the dll into the root folder of the project, if its built as part of the visual studio solution? I expected that adding a reference to the dll project would suffice, but it doesn't appear to be the case. Do I need to write some shell script? Is there some UI button in VS that i can press? Some specific package or manifest xml command?

 

I am not familiar with PSF. How is it relevant for this situation?

 

Regarding .txt files, i am not even at a stage where i want to be able to find them within the package.

My problem is making sure they are added to the package in the first place. Is there a common way to do that?

 

Thank you.