Having trouble creating an MSI for Windows Mobile apps?

Well, you are not the only one… Creating an MSI file for application distribution is really simple, but when you want to distribute an application that runs on the Windows Mobile environment, it is not that simple any more. This is especially true if you are new to Windows Mobile development.

Why a CAB if I want an MSI?

The answer is "multiple hardware platforms", you obviously want to deliver a well developed solution, and your application will probably be rolled out to different hardware. What you want to do is create a CAB file containing the application as compiled for that particular platform (Windows Mobile Professional vs. Windows Mobile Standard). You may be even looking at releasing the application to different OS versions and even different processors. Well, that might require some tweaking on your part to deliver the best performing application for each platform, OS, and processor… bummer.

So the best approach is to create multiple CAB files, each one with all the corresponding application requirements. and finally create the MSI file that contains all of them. Easy, right? not so fast…

Once you have all the CAB files you need, you can create an INI file that lists all the mutually exclusive CAB files in the package. For example DotNetCF would be one package, SQL2k5 would be another and the third one would be your application. Each of those packages would be a set of CAB files of which only one would be installed to the mobile device. In other words, you would be installing 3 CAB files, one from each package. However, each package will have many files; as many as different platforms you are deploying to. You will create an INI file for each package you want to create. This INI file will have the list of all mutually exclusive CAB files in that package.

While you can create an MSI project pretty quick, the MSI projects are targeted at delivering the application to a PC and not a mobile device. So you need to "trick" the MSI installer into not only copying the cab file into a PC folder, but also running the application installer provided with ActiveSync (yes, the one that runs when you add/remove programs in ActiveSync). Coupled to that, you may need to distribute several other packaged CAB files such as the .Net Compact Framework, SQL Server Compact, etc. The default project for creating MSIs only has automation to copy files in certain folders, so you can use code in a custom installer class where you can specify to run CEAppMgr.exe for as many CAB packages as you want.

To make things short, you would be running a call to unpack the right CAB file from each INI file you created. CEAppMgr will take care of deciding which one is right for your device, out of all the options you list in the INI file, so all you need to do is make the right call in that custom installer.

Now, out on the web I have noticed that people are having trouble making the right call. This is because they are not allowing the process to wait enough time to call it again for unpacking the next set of CAB files listed in the next INI file… that is because in the call, they need to use .WaitForExit() at the end of the call. The call in the custom installer should look like this:

System.Diagnostics.Process.Start(appMgrPath, "\"" + Path.Combine(installPath, CEAPPMGR_NETCFXv2_INI_FILE) + "\"").WaitForExit();

System.Diagnostics.Process.Start(appMgrPath, "\"" + Path.Combine(installPath, CEAPPMGR_SQLCE2K5_INI_FILE) + "\"").WaitForExit();

System.Diagnostics.Process.Start(appMgrPath, "\"" + Path.Combine(installPath, CEAPPMGR_INI_FILE) + "\"").WaitForExit();

If you have to make several calls, and you don’t use "wait for exit", then the process may overlap and fail from time to time. It will not fail every single time, but it will not work correctly every single time.

Got the MSI… but need to rebuild my projects: how?

This is the really easy part. If you have all projects as part of a solution, then it will be easy to rebuild each project (application, then CAB, then MSI) and just pick up the MSI file from the Release folder under the MSI project folder.

Now that you have the basics, lets get to build that MSI!

Don’t hesitate to post your comments here or even better: go to our forums for posting specific help with your project’s MSI package.

About Diego Samuilov

Editor in Chief/Founder Diego Samuilov is an executive, consultant, IT strategist and book, e-book and web published author. Diego has worked in Microsoft’s environments since 1990. Since then, he has successfully filled many positions related to the Software Development lifecycle. Having worked as a developer, analyst, technical lead, project lead, auditor and, since 1996 a project manager, manager, director and VP in the Software Development, Server, Desktop and Mobile environments. Diego is very passionate about the software development process, which has played a great part in his skills development. Since the introduction of the first ever PDA (the Apple Newton MessagePad) in 1994 and Windows CE in 1998 he has pioneered and pushed the envelope in the field of mobile software development. He has developed many solutions used in mobile markets, desktop and server environments. He participates in public and private developer community events. He actively collaborates with the community at support forums and blogs. Diego is the author of "Windows Phone for Everyone" available [HERE].