Perl programmer for hire: download my resume (PDF).
John Bokma MexIT
freelance Perl programmer

Compiling .NET Compact Framework applications without VS

Thursday, November 23, 2006 | 2 comments

When I bought my Dell Axim X51v PDA, or pocket PC, I had shortly after plans to write some small programs for it. Since I had already played a bit with C# several years ago I was hoping that Microsoft also made a .NET Compact Framework software development kit (SDK) available that I could use without Visual Studio, and use either via the command line or #develop (SharpDevelop), an Open Source Development Environment for .NET.

But alas, the "Windows Mobile 5.0 SDK for Pocket PC" page clearly stated under system requirements "Visual Studio 2005 Standard, Professional, and Team Suite Editions". Some time earlier I had already found a tutorial on compiling .NET CF (Pocket PC) applications without Visual Studio.NET, but since it was a bit outdated, I was hoping that the instructions in this tutorial were no longer needed, but as somewhat expected an attempt at installing the WM 5.0 SDK reported Visual Studio not being present and that installation was not possible.

.NET related files required

So I decided to download what I thought was needed based on the aforementioned tutorial. I had already downloaded the .NET Compact Framework 2.0 Service Pack 1 Redistributable and installed it both on my development computer and Dell Axim, but the full list that worked for me is:

Extracting and renaming the required DLL files

After installation I ended up with two folders in C:\Program Files\Microsoft.NET\SDK: CompactFramework and v2.0. The former has a v2.0 sub folder and somewhat deeper various CAB files. I needed to pick the right one to obtain the DLLs for my device. After consulting .NET Compact Framework Version 2 .CAB Files Explained it was clear that this was NETCFv2.wm.armv4i.cab because my Dell Axim X51v is a Pocket PC running Windows Mobile 5.0 on a ARMV4I processor.

So I created a wm.armv4i.dll folder under the v2.0 sub folder of the CompactFramework folder and extracted the files contained within NETCFv2.wm.armv4i.cab into this newly created folder:

 11/23/2006  10:00 PM    <DIR>          .
 11/23/2006  10:00 PM    <DIR>          ..
 05/09/2006  05:59 AM           463,296 00System.007
 02/02/2002  03:02 AM            58,312 0mscoree.005
 05/09/2006  09:42 AM            18,728 CGACUT~1.020
 05/09/2006  05:59 AM            14,296 CUSTOM~1.019
 05/09/2006  05:59 AM            31,208 MICROS~1.017
 05/09/2006  05:59 AM           351,200 MICROS~2.016
 05/09/2006  05:59 AM           183,288 MICROS~4.018
 05/09/2006  06:28 AM           815,048 MSCORE~1.002
 05/09/2006  09:42 AM            58,312 MSCORE~1.021
 05/09/2006  05:59 AM           909,768 mscorlib.006
 05/09/2006  05:58 AM                51 NETCF2~1.001
 05/09/2006  06:33 AM           248,272 NETCFA~1.003
 05/09/2006  06:33 AM           160,208 NETCFD~1.004
 05/09/2006  09:42 AM             1,054 NETCFV~1.000
 05/09/2006  06:29 AM            49,104 NETCF_~1.999
 05/09/2006  05:59 AM         1,027,528 SY40C7~1.013
 05/09/2006  05:59 AM           693,712 SY4317~1.015
 05/09/2006  05:59 AM            75,224 SY726F~1.009
 05/09/2006  05:59 AM            49,648 SY9B57~1.012
 05/09/2006  05:59 AM            62,944 SYC6B2~1.010
 05/09/2006  05:59 AM            17,368 SYSTEM~1.014
 05/09/2006  05:59 AM            58,320 SYSTEM~3.008
 05/09/2006  05:59 AM           240,608 SYSTEM~4.011
 05/09/2006  09:42 AM             6,395 _setup.xml
               24 File(s)      5,593,892 bytes
                2 Dir(s)   2,829,742,080 bytes free

C:\Program Files\Microsoft.NET\SDK\CompactFramework\v2.0\wm.armv4i.dll>

Since the contents of this folder didn't match the one given in the compiling .NET CF (Pocket PC) applications without Visual Studio.NET tutorial I checked the contents of _setup.xml. And this file contained several information how the files should be renamed from their short 8.3 names into longer, more clearer names. So after careful reading of both the aforementioned tutorial and _setup.xml I came up with the following rename.bat file:

ren mscorlib.006 mscorlib.dll
ren 00System.007 System.dll
ren SYSTEM~3.008 System.Drawing.dll
ren SY726F~1.009 System.Messaging.dll
ren SYC6B2~1.010 System.Web.Services.dll
ren SYSTEM~4.011 System.Windows.Forms.dll
ren SY9B57~1.012 System.Windows.Forms.DataGrid.dll
ren SY40C7~1.013 System.Xml.dll
ren SYSTEM~1.014 System.Net.IrDA.dll
ren SY4317~1.015 System.Data.dll
ren MICROS~2.016 Microsoft.VisualBasic.dll
ren MICROS~1.017 Microsoft.WindowsCE.Forms.dll
ren MICROS~4.018 Microsoft.WindowsMobile.DirectX.dll
ren CUSTOM~1.019 CustomMarshalers.dll
ren CGACUT~1.020 cgacutil.exe.-500~-500~ARMV4I
ren MSCORE~1.021 mscoree.dll.-500~-500~ARMV4I

Since I was not sure (and still am not) if this covered all I decided to compile a very small C# test program and try to run it on my PDA.

Compiling Hello, PDA World!

In order to test the installation I entered the following test program using TextPad:

using System;
using System.Windows.Forms;

public class HelloWorld {

    public static void Main() {

        MessageBox.Show( "Hello, PDA World!" );
    }
}

and saved the newly created file as HelloWorld.cs.

Next, I opened a command window with the current working dir set to the folder containing HelloWorld.cs and entered the following instructions to set up the development environment:

pushd C:\Program Files\Microsoft.NET\SDK\v2.0\Bin
sdkvars.bat
subst n: "C:\Program Files\Microsoft.NET\SDK\CompactFramework\v2.0\wm.armv4i.dll"
popd

Then I compiled the C# source file as follows (one long line):

csc /noconfig /nostdlib /r:n:\mscorlib.dll /r:n:\system.dll
/r:n:\system.drawing.dll /r:n:\system.windows.forms.dll /target:winexe HelloWorld.cs
"Hello, PDA World!" on Dell Axim X51v.
"Hello, PDA World!" on Dell Axim X51v.

I used Microsoft ActiveSync to copy the file to the Dell Axim, and when I started HelloWorld.exe I was greeted with the by me now well known first time execution warning: "The program is from an unknown publisher. Running it can possibly harm your device. Do you want to continue?". I tapped "Yes" and was greeted by a small pop up message box containing the message "Hello, PDA World!".

Related

Also today

Please post a comment | read 2 comments, latest by John Bokma | RSS feed