Thursday, February 14, 2008

How to deploy the .Net Compact Framework and SQL Server Compact Edition

If we've developed a .Net Compact Framework application, we'll need to have the .Net CF installed on the device before the application is launched. It's the same case if we're using SQL Server Compact Edition, it should be installed on the device or our application will not able to open the database. So very obvious, but so very important. It's particularly important when we're designing a deployment strategy.

We already know how to create a .cab installer for the application, but we also know that there is no way to define dependencies in a cabinet file. We cannot say that depends on the compact framework cab files and/or the SQLSCE cab installer.

And how can we do it?

During the development process, Visual Studio deploys both components to the device/emulator when needed, but this is not a feasible method when your app has been brought to production. We need to check manually if the .Net CF and SQLSCE are installed on the device and deploy them if needed. I suggest the following options to do this:

1) Using a desktop Installer

*If a desktop installer is an option* in your scenario, you can build an MSI which register the .cab installers, and using ActiveSync/WMDC checks if it's necessary to deploy and install each one. You can take a look at this very helpful article by Stan Adermann explaining how to create an MSI Package that detects and updates the .Net Compact Framework. Nice stuff.

2) Using a third party update library

You can use a library like the Q4Tech Mobile Updater Application Block which is an open source library which can be customized according with your scenario, or some similar one.
Update (04/29/2009): The Q4Tech Mobile Updater has been moved to the MobileContrib project at codeplex under MS-PL License.

3) Create a light-weight native installer

You can create a native application (i.e. using Visual C++) which will be installed on the device and should check whether the .Net CF is already installed, get the cab if needed, and launch it. Once the .Net CF is installed it can continue updating SQLSCE and the app assemblies. An alternative is just use this native installer to install a new managed installer application which can do the remaining work.
This option needs also a server-side component to publish the .cab installers to the native client. It can be in its minimal version just a web server publishing the .cab files.

You can choose the option which fits better on your scenario, and probably another good option for you can be to use third-party products or if you want, you can even include separate framework files on your .cab file, but it needs lot of work and it will carries on with security problems if you need to sign your application.

As you can see, deployment is not a trivial part of the mobile application development. The deployment strategy you design will have a big impact on the success of your project. I hope this post helps you achieving that success. Stay tuned!


Anonymous said...

One option with SQL Server Compact Edition is to simply deploy the engine dlls alongside your application. This is the cleanest/simplest way to deploy SSCE as it means you never have to worry about dependencies during install or uninstall.

There are of course some penalties in this deployment strategy. Of course if there are multiple applications using SSCE then it would make sense to install it in the GAC for all applications to use but imho it's not worth the additional headache for deployment.

Hopefully the new Sync Services framework, which we are hoping will have a device implementation soon, will also deploy this way (ie either via installer or through assembly deployment)

Jose Gallardo said...

Thanks Nick for your contribution. You're absolutely right, that is a very good option if you just need to deploy SQL Server Compact Edition with your app.
It's nice to have you here! Hope hear from you again soon.