Wednesday, November 7, 2007

Building a .cab installer which registers the assemblies in the .Net Compact Framework GAC

Update: I've recently posted a new article about How to create a Smart Device .Cab Installer which is intended for more general purposes than registering assemblies in the GAC. If you're looking for that it can be very helpful. (02/06/2008)

Continuing with the example in the previous post, let's see how we can use Visual Studio 2005 to create a .cab installer which will register the assemblies in the GAC.

The first step is to create a new Smart Device CAB Project:

image

Open the File System Editor (it could be already open) pushing the button on the Solution Explorer toolbar.

image

Create a new "Global Assembly Cache" folder on the file system editor: Right Click on "File System on Target" - "Add Special Folder" - "Global Assembly Cache Folder"

image

Add the assemblies to the "Global Assembly Cache Folder" using the context menu "Add - File" option or just drag & drop them to the folder:

image

Now, you have both files on the GAC Folder. You just need to build the .cab project.

If you take a look at the build result, you'll see the following files:

image

Please pay special attention to the "MyUI.GAC" file. This file is a .gac file with the following content:

%CE2%\MyCustomControls.dll
%CE2%\MyExtendedControls.dll

When the .cab is installed on the device, all the assemblies and the .gac file will be placed on the "\Windows" folder. The next time a .Net CF application is launched, the assemblies will be registered in the GAC.

If you uninstall the .cab from the device (i.e. using the "Remove Programs" option), the .gac file will be removed and the next time a .Net CF app is launched the also assemblies will be removed from the GAC, as we've seen in my previous post. It's just very simple! isn't it?

10 comments:

Marcio Guerra said...

Hello Jose ..
I have a doubt you to help me.
I created one .CAB for my project and worked perfectly, but every time I change the battery or need to reboot smart device, the application is lost. How do to keep the application in the smart device?

Congratulations on BLOG has been very useful to me.

Marcio Guerra
Sao Paulo - Brazil
e-mail: guerra.marcio@gmail.com

Jose Gallardo said...

It looks like you've a Pocket PC running a WM version prior to Windows Mobile 5. Persistent Storage is new for Pocket PC from WM5 (but it's included in all the smartphone versions). The only alternative you have is to install your app into a storage card (CF, SD, etc). Thanks for your feedback!

Thomas Stock said...

Jose,

I have a similar problem as Marcio.

My application stays installed after changing the battery, because my mobile device has a "backup" function which backups /Windows into /Backup/Windows. On Cold reboot, the device copies the /Backup/Windows folder back to the regular /Windows folder.

Now, the problem is that somehow the .NET framework 3.5 and (I think) SQL Server CE 3.5 are lost after such a cold reboot.

I wonder if any of your blog posts could be used to solve this problem?

I can't work with CF cards or images on the device. It's a Datalogic Skorpio Scanner with windows CE 5.0.

nickblair said...

Hi Jose
I have followed your blog re build a smartdevice project .cab file and done registered the gtac assemblies etc. but I keep on getting the same error 'cannot build cab file'. Can you give me possible causes for this. (I have successfully deoployed the device before using vs2008 (I am using .net cf 3.5)

nickblair said...

Hello Jose,
Sorry, I mean the error is 'Cab Wizard encountered an error- see output window for details' I presume this means .log file, well this does not give anything except .cab file cannot be created
Best Regards
Nick

nickblair said...

Hi Jose,
The problem is with the third party software I am referencing (Franson Bluetools). When I create a new 'hello world' project without the reference the cab builds fine, when I include the reference I get the original error. The funny thing is that when I deploy app with the included reference with vs2008 it works as it should, there is only a problem when I try to create a cab file. Are there any precautions when referencing a non microsoft dll?

nickblair said...

Hi Jose,
I don't know what I did maybe refresh dependencies but the cab file now builds. The only other thing I have to do is to check for and load prerequisites for all 3 mobile platforms automatically.(pocketpc,mobile5,mobile 6 with cf3.5). Jose mentioned the one on MSDN help but it is written in 2003 so would not be applicable for the latter 2 PDA's or the cf3.5 cab files

Jose Gallardo said...

Hi Nick,
This is a very common scenario, and you can follow several approaches according to your needs.
I've already posted about it on
How to deploy the .Net Compact Framework and SQL Server Compact Edition
and
Detecting what .Net CF version is installed on your device
You can also take a look at
Setup.dll Sample and Walkthrough: Terms & Conditions / End User License Agreement for a Smart Device CAB installer for understanding what is a Setup.dll and how you can build one.
HTH!

nickblair said...

Hi Jose,
Is there a problem installing the cab file
NETCFv35.wm.armv4i.CAB
onto a mobile 6 pda?
This is the file the attempts to load to the device when deploying from visual studio but when I do this and also from a setup file the installation in both cases is unsuccessful.
Regards
Nick

Anonymous said...

Hi Jose,
Is there any way I can customize my cab to install particular files on a specific device while other files on a different device, while using the same cab file for installation on both the devices.

Would greatly appreciate your help!

thanks,
curious1