This post focuses on how to create a setup package to deploy applications to Windows Mobile device.
Sure, it is easy to start with developing a Smart Device application. Visual Studio provides us the Smart Device project template to get started. During the course of development, you can test your application by pressing F5. Visual Studio automatically launches the emulator and starts on the deployment of the application on the emulator. Everything is easy (and hidden from view!!).
Well, after the development, it is time to deploy your application. You would need to present an acceptable form of installer for your end users. For Windows mobile, you have a choice of packaging the application as a cab file. But then, the users have to transfer the cab file on their mobiles and launch the cab files on the mobile. It is messy and complicated job to ask for and more often than not, the end users would demand an easy method to install on their mobiles, like the Windows installer they are used to on their desktop.
So, how do we go on creating that elusive MSI? The answer is fairly simple and leverages Microsoft Active Sync (available on Windows XP and earlier) and Windows Mobile Device Center (on Vista) to install the windows mobile application on the device. Active Sync/Windows Mobile Device Center is the sync program to keep your Outlook contacts/files in sync between the desktop and the mobile device. It also enables one to install applications on the device and this is what we would transparently run and install the application on the mobile, while providing a pleasant user experience.
I will discuss the pre-requisites and detail out the steps to be done to create an MSI installer and how to install on the emulator. The same installation process can be followed to install the application on the windows mobile device. Installing on the emulator is a big advantage, since you have a chance to do a dry run and do a check for the working of the application on the emulator before you install on the actual device!
Before you start
If you have Windows XP or earlier, ensure that you have Active Sync 4.5 installed. Note that, Active Sync 4.5 does not work on Vista. You can get it from the Microsoft site through this link.
Those having Windows Vista, download Windows Mobile Device Center 6.1 from here. Note that there is a pre-installed Windows Mobile Device Center that runs on Windows Vista, but that just launches a simple program to just transfer files on the emulator. The actual installation manager program is handled by the CEAppMgr.exe which gets installed only when you download and run the Device Center 6.1 installer!! By the way, don't get confused seeing a driver update installer (drvupdate-x86.exe) at the Microsoft download site. This is the download containing the Windows Mobile Device Center program and drivers in a single package!
Components required for the MSI Setup Package
There are 2 components that are required in creating a setup windows installer (MSI) package. One is the cab file and other is a custom installer.The mobile device application is packaged into one or cab files. The custom installer is required to guide the installation of the cab files to the mobile device by launching the CEAppMgr.exe.
Its easy to setup a Smart Device Cab project; once you have added and configured the Cab Setup project to your solution, you can move ahead to create a Custom Installer project.
Creating the Custom Installer
To your Smart Device solution, add a Windows Class Library project. Call it CustomActionSetup. Remove the class1.cs and add a new Installer class item, say CustomAction. You should code the AfterInstall and AfterUninstall event handlers of this class to launch the CEAppMgr.exe similar to this: System.Diagnostics.Process.Start(ceAppMgrPath, iniFilePath);
The iniFilePath is the path to a Setup.ini. This Setup.ini at the minimum should list the cab files, the application version and name of application.
Creating the MSI package
To the Smart Device Solution, add a Windows Setup and Deployment project. Add the files from the other project outputs like CustomActionSetup.dll (from the Custom Installer Project), the TestMobileSetup.cab (from Smart Device project) file and the Setup.ini file.The MSI package can now be created. However, we still need to tell the MSI package to run the CustomActionSetup.dll, which in turn calls CEAppMgr.exe for installation to the device, after installing the cab files.
To do this, setup a Custom Action (right click on the project; View -> Custom Action). Add the custom action to the Install action and choose the CustomActionSetup.dll in the Application folder.
Build the MSI project to get the MSI file.
Installing on the emulator
Start the emulator through Visual Studio (Connect To Device button in the toolbar). Once the emulator is started, launch Device Emulator Manager (under Tools menu). Cradle the emulator you just started. Now, you can run the MSI file. The installation first installs on your desktop and seamlessly installs on the emulator. You will get a message as such. The emulator also will show a message saying Cab file installed.
Congratulations! The installation is done. To run the app, check the Program files (Program shortcut menu) on the emulator.
Installing the application on the mobile device is very similar. You first connect the device through USB and launch ActiveSync to connect to the device. Then run the MSI file on your desktop.
Uninstalling the application can be done through the ActiveSync/Windows Mobile Device Center.
Though it seems easy to implement at a glance, the real issues come forth during creating the MSI setup package and one is at a loss to understand what has happened.The steps in the article give a concise reference to the key items involved in building a MSI package to install an application in a mobile device. You can contact me through this blog for sample code pertaining to this article.
More recently we came across a strange issue when installing an application on the mobile that referenced a web service. I will cover the issue and the resolution in my next post!
Thursday, April 30, 2009
Subscribe to:
Post Comments (Atom)
2 comments:
Thank you for the article.
how to debug the MSI package? During the installation I am getting error.
Waiting for your reply.
You can use standard debugging methods like logging to a flat file
Post a Comment