Click here to Skip to main content
15,860,859 members
Articles / Mobile Apps

Windows Mobile Development Without Visual Studio

Rate me:
Please Sign up or sign in to vote.
4.90/5 (52 votes)
8 Jan 2009CPOL17 min read 319.8K   1.6K   116   59
A guide to get a Windows Mobile Professional dev environment up and running for those who cannot acquire Visual Studio.

Introduction

Every now and then, the question resurfaces in MSDN Support Forums on the minimal toolset for developing for Windows Mobile. Sometimes, the inquiring person cannot afford the best development tool available (Visual Studio). While it is possible to perform Windows Mobile development with only the .NET Framework SDK, I've never tried it until now (I usually use VS 2008 Professional). I've just performed a clean installation of Vista on one of my computers, so I am taking its clean state as an opportunity to both try to perform some development without Visual Studio and validate what is needed.

Why Not Use Visual Studio Express?

The Express editions of Visual Studio are free. So why not use those instead? The reason is simple. Presently there is no version of the Express edition of Visual Studio that can be used for Compact Framework of Mobile Device development.

What Does this Article Cover?

The reader of this article should already know how to program in C# or have resources for learning the language. Similarly, the reader of this article should already have access to resources for learning Windows Mobile. The aim of this article is not to teach one how to program. Rather, it is a guide to getting the minimal toolset up and running for Windows Mobile development. While this article has the information to create a minimal development environment on an extreme budget, I don't encourage this path if you can afford Visual Studio. Your time is valuable, and using Visual Studio will help you to use your time more effectively. It provides a number of feature enhancements that will improve a developer’s productivity dramatically. But, if you wanted to do some Windows Mobile development without making a financial investment in the tools, then read on.

Links to resources

Throughout this article, I will make references to resources that you can download for free. I've listed the links to these resources below:

Minimum Software Needed

Presently, there are two framework versions that you could elect to use; the 2.0 Compact Framework and the 3.5 Compact Framework. The 3.5 Compact Framework is a superset of the 2.0 Compact Framework; it has all of the features of the 2.0 Compact Framework plus some other functionality (such as the Windows Communication Foundation and some media related functions). The framework that you choose should be a function of your current needs and the devices you will target. Windows Mobile 6.0 and 6.1 has the 2.0 framework included as part of the ROM image. Unless I need functionality in the 3.5 framework, I generally will target the 2.0 framework. Windows Mobile 5 devices do not have the 2.0 or 3.5 CF preinstalled, so regardless of the framework, you select the .NET CF redistributables that will need to be installed on top of the device's default image.

The Compact Framework is included with the .NET 2.0 and 3.5 SDKs, though it isn't installed by default. For the 2.0 SDK, the Compact Framework can be found in NETCFSetupV2.msi in the Compact Framework directory after the installation of the SDK (c:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\CompactFramework). For the 3.5 SDK, the Compact Framework is displayed is an installation option that is unselected by default. Ensure that you select it. And yes, you can install both frameworks on the same computer without conflicts. Go ahead and install both framework SDKs and the Compact Frameworks. After you've installed the software, run Windows Update to ensure that you have any updates that were released for the software.

Image 1
These are the default settings for the .NET 3.5 Framework installation. Notice that the .NET Compact Framework is not selected by default. Make sure it is checked when you perform the installation.

File Locations

Once you have installed the SDKs, you will want to know where some important files are. Assuming you selected the default installation locations, you can find your files in the following locations:

ResourceLocation
3.5 Compact Framework assembliesC:\Program Files\Microsoft.Net\SDK\CompactFramework\v3.5\WindowsCE
2.0 Compact Framework assembliesC:\Program Files\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE
Command line compilerC:\Windows\Microsoft.NET\Framework\v2.0.50727

Compiling your First Program

For this next section, we are going to compile a “Hello World” program. The emphasis here is on the compiler, not the code. So, I will start off with a simple example. Open Notepad, and type the following (or copy it from the code included in this article):

C#
using System;
using System.Drawing;
using System.Windows.Forms;

namespace MyNamespace
{
   class HelloWorldForm : System.Windows.Forms.Form
   {
        Label lblHello;
        Button btnClose;

        public HelloWorldForm()
        {
            this.Text="Hello World Sample";
            btnClose = new Button();
            lblHello = new Label();
            btnClose.Click += new EventHandler(btnClose_Click);
            btnClose.Text="Close";
            btnClose.Location = new Point(10,100);
            btnClose.Size = new Size(200,50);
            lblHello.Text = "Hello World!";
            lblHello.Location = new Point(10, 10);
            lblHello.Size = new Size(200,50);
            SuspendLayout();
            this.Controls.Add(lblHello);
            this.Controls.Add(btnClose);
            ResumeLayout(false);
        }

        void btnClose_Click(object sender, EventArgs args)
        {
            this.Close();
        }

        [MTAThread]
        static void Main()
        {
            HelloWorldForm mainForm = new HelloWorldForm();
            Application.Run( mainForm );
        }
    }
}

Save the file as HelloWorldForm.cs.

When the .NET SDK is installed, it creates an icon in Program Files->Microsoft Windows SDK 6.1, named “Cmd Shell”. Clicking on this icon will open a command prompt instance with its path variable set such that the command line compiler will be found. Click on this icon to open the command prompt, and then navigate to the directory in which you've saved the source file. Type the following:

csc HelloWorldForm.cs

After running, you will have a new file named HelloWorld.exe in the same folder. Go ahead and run it. You'll see a simple form displaying the text “Hello World” and a “Close” button. This executable won't run on your mobile device because the compiler linked it to the desktop framework assemblies. Let’s recompile it the appropriate way for the Compact Framework. I have included two batch files with this article to compile the project against the 2.0 CF and the 3.5 CF. If you have installed the SDKs in a place other than their default locations (or if you have a 64 bit edition of Windows, in which case the paths will be different), you will need to update these batch files.

SET FrameworkAssemblyPath="C:\Program Files\Microsoft.Net\SDK\
				CompactFramework\v3.5\WindowsCE"
REM the following should be on one line but is broken into 
				several lines for readability.
csc.exe /nologo /nostdlib /noconfig /out:HelloWorld.exe
        /r:""%FrameworkAssemblyPath%\mscorlib.dll""
        /r:""%FrameworkAssemblyPath%\System.dll""
        /r:""%FrameworkAssemblyPath%\System.Windows.Forms.dll""
        /r:""%FrameworkAssemblyPath%\System.Drawing.dll""
        HelloWorldForm.cs

I'll explain what all of the above does:

  • SET FrameworkAssemblyPath="C:\..." - Sets a variable to the path to the Compact Framework assemblies so that we do not have to keep typing it.
  • csc.exe - The C# compiler. Were this a VB.NET program, I would have used vbc.exe instead.
  • /nologo - Suppresses the compiler from displaying copyright text.
  • /nostdlib - Tells the compiler not to link to the standard desktop assemblies.
  • /noconfig - Prevents the compiler from importing a desktop related configuration.
  • /out:HelloWorld.exe - The name to assign to the resulting assembly.
  • /r:""%FrameworkAssemblyPath%\xxx.dll"" - Tells the compiler to link to a specific assembly.

After compiling the program, you will have an executable that will run on a Windows Mobile device. You could run the application now, and it will run on the desktop. But, don't make the hasty conclusion that all Compact Framework programs will run on the desktop.

Testing the Program Without a Physical Device

Let’s assume that you do not have a physical Windows Mobile device. You can download Windows Mobile emulators from the link at the top of this article. The emulators are available localized in a number of different languages. There are two primary methods available for copying files onto the emulator. One method is to share a folder with the emulator, and the other is to dock the emulator to ActiveSync (on Windows XP) or the Windows Mobile Device Center (on Vista). I will walk you through sharing a folder first.

Sharing a Folder on the Desktop

Start up one of the Windows Mobile Professional emulators. Open the “File” menu and select “Configure”. At the bottom of the “General” tab is an option called "Shared folder". You can enter a path here to a folder on your desktop. After selecting “OK”, the folder will appear within the emulator as a storage card. Enter the path to your .NET CF executable. On the emulator, navigate to the storage card on the device and open your executable.

Image 2
Here, you can see the HelloWorld executable in a shared folder on my desktop and the same folder within the emulator. I'm using the Japanese emulator here (the emulators are available localized in several languages).

Connecting the Emulator to Active Sync

To dock the emulated Windows Mobile device while it is running, select Program Files->Windows Mobile 6 SDK->Tools->Device Emulator Manager. You'll see the emulated device listed. Right-click on it, and select "Cradle". After a few moments, the device will show up when you open Windows Explorer as an attached device. You can then copy the program to the device.

Image 3

Connecting to a Physical Device

For a physical device, you would only need to connect your Windows Mobile device to a computer with Active Sync or the Windows Mobile Device center installed. It doesn't matter if you establish a partnership with the device or not. The device will be visible when you open the file explorer, and you can copy your program directly to the device’s file system.

Running the Program

Regardless of the method you choose to get the file onto the device, you can now run it. Go ahead and open the executable.

Oops! An error appears! “The application requires a newer version of the Microsoft® .NET Compact Framework than the version installed on this device.” Let’s first verify the version of the Compact Framework that is on your device. Open the file explorer and navigate to the \Windows folder. Run CGACUTIL.EXE. It shows that only the 2.0 framework is installed (or 1.0 on a Windows Mobile 5 device). You will need to install the appropriate framework.

Installing the 3.5 Framework to the Device

Look in c:\Program Files\Microsoft.Net\SDK\CompactFrameowork\v3.5\WindowsCE\, and you will find several CABs for .NET CF installations. You want to install the one named “NETCFv35.wm.armv4i.cab”. Copy this file to the device’s file system, and then open it using the device’s file explorer to install it. After installing it, run CGACUTIL.EXE again. It will report that you have the 3.5 framework installed. Try running the HelloWorld executable again. Success!

Installing the 2.0 Framework to the Device

If you have installed the 3.5 framework, then you don't need to install the 2.0 framework. If you would like to install the 2.0 framework, then look in c:\Program Files\Microsoft.NET\SDK\Compact Framework\v2.0\WindowsCE\wce400\armv4, and you will find a CAB named “NETCFv2.ppc.armv4.cab”. Copy the file to the device’s file system, and open it using the device’s file explorer to install it. After installing it, run the CGACUTIL.exe utility again. It will report that you have the 2.0 framework installed. If you run HelloWorld now, it will succeed.

Image 4
Our "Hello World" program running on the emulator.

Where is the Debugger?

There is a command line debugger in the .NET framework SDK named cordbg.exe. The debugger previously supported connecting to a smart device. Presently, it does not (though the MSDN documentation on cordbg.exe will suggest otherwise). Because of the absence of this debugger, if you want to effectively be able to debug your programs, you have no choice but to purchase Visual Studio.

Adding an IDE : SharpDevelop

A good IDE is a must for development. And, the best IDE that you can acquire for free for your Compact Framework development will be SharpDevelop. SharpDevelop is an open source .NET IDE. Version 3.0 of SharpDevelop has support for both the 2.0 and 3.5 Compact Frameworks. After installing SharpDevelop, you will also want to ensure the .NET 3.5 CF Powertoys are installed. If you do not install them during the compilation of a Compact Framework program, you'll receive a rather vague error about CSharp.targets not being found during compilation. Those already familiar with Visual Studio will not find any part of the following description of SharpDevelop to be ground breaking; these features are present in Visual Studio too in an almost identical form.

Compilation with SharpDevelop is a much better experience than from the command line. Do you remember the multitude of /r arguments that had to be passed to the command line compiler for the HelloWorld program that we worked with earlier? In SharpDevelop, those references are managed graphically, and the most common ones will automatically be included in your solution, by default. A screenshot of the representation of references is shown below. To include another assembly in this list, right-click on the "References" folder and select "Add Reference". A dialog will appear listing the assemblies that could be added to the project.

Image 5

The source editor in SharpDevelop is much easier on the eyes than a standard text editor. It includes auto-complete, which will be a big help in two ways: autocomplete will allow you to reference entities with long names without actually typing the complete name of the entity, and also acts as a type of quick reference to the members of your classes.

Image 6

SharpDevelop uses a tabbed editor interface to allow you to work among multiple open files.

Image 7

SharpDevelop is also able to work with solutions that were built in Visual Studio. I downloaded BillLange1968's Game source code and opened it in SharpDevelop. Without any modifications, the code compiled and ran in SharpDevelop.

Image 8
Editor window of SharpDevelop with an autocomplete pop-up displaying.

Creating a New Project with SharpDevelop

Once you have SharpDvelop installed, you can begin a new project by selecting the menu File->New->Solution. A dialog appears asking what type of project you would like to create. Expand the C# section of this dialog, and click on "Compact Framework". Select the version of the Compact Framework that you wish to use from the drop-down in the upper-right corner of the dialog, and enter a name for your project. Click on "Create", and your project will be created. After the creation of your project, if you expand the file tree on the left, you will see a total of three files in your project (Assembly.cs, MainForm.cs, and MainForm.Designer.cs). Both MainForm.cs and MainForm.Designer.cs are part of the same class. MainForm.Designer.cs is meant to hold all the code related to your form's layout, and MainForm.cs is meant to hold the logic and behavior of the form. In its present state, you could compile and run this program (though it will only display a blank form).

Once again, the emphasis here is on the development environment and not on the code. So, we are going to do something very basic with the code. This form will have a single button. If the user clicks on the button, a dialog will open, displaying out the "Hello World" text. Open MainForm.cs, and just before the Main method, enter the following to declare a button:

C#
Button btnShowMessage;

Open MainForm.Designer.cs and navigate to the InitializeComponent method. At the end of the method, type the following:

C#
btnShowMessage = new System.Windows.Forms.Button();
btnShowMessage.Text="Show Message!";
btnShowMessage.Size = new System.Drawing.Size(220,100);
btnShowMessage.Location = new System.Drawing.Point(10,10);
this.Controls.Add(btnShowMessage);

To help ensure that you have made no mistake, compile the program by selecting the menu Build->Build Solution. If you have made any syntax errors, they will be listed at the bottom of the screen. After correcting the errors (if any), we need to add another form to our project that will be the resulting dialog. Select the sequence File->New-> File. You will be asked if you want to create a standalone file or a file inside the project. Select the option to create the file within the project. When the New File dialog opens, select "Windows Application" from the "C#" group on the left, and "Form" from the templates area on the right. Enter "MyDialog.cs" for the file name, and then press "Create." Two files will be added to your project: MyDialog.cs and MyDialog.Designer.cs.

Image 9

Open MyDialog.Designer.cs and navigate to the InitializeComponent method. At the end of the method, enter the following:

C#
System.Windows.Forms.Label myLabel = new System.Windows.Forms.Label();
myLabel.Text="Hello World";
myLabel.Location = new System.Drawing.Point(10, 10);
myLabel.Size=new System.Drawing.Size(200,40);
this.Controls.Add(myLabel);

Save your work, and compile it again to ensure that there are no syntax errors. We now have our main window and a dialog defined. The only thing left to do is to add code that will respond to the user pressing the button by displaying the dialog. Go back to MainForm.cs. In the MainForm constructor on the line after the call to InitializeComponent, type the following line:

C#
btnShowMessage.Click+= new EventHandler(btnShowMessage_Click);

After the constructor, define a new method to react to the user's click. Add the following code to create the method:

C#
 void btnShowMessage_Click(object sender, EventArgs e)
{
    MyDialog md = new MyDialog();
    md.ShowDialog();
}

That is the last of the code that is needed. Compile the project one more time. If it compiles without error, then select Debug->Run to run the code. A window will appear with the button. Clicking on the button will result in the dialog displaying. However, this program is running on the desktop and not on the mobile device. A present limitation of SharpDevelop is that it will not be able to debug programs running in the device emulator or on an actual phone. For this program, there aren't many consequences from testing it within the desktop. If we had written a program that was using functionality that is usually not implemented on a desktop (such as sending an SMS message), or if we had made P/Invoke calls, then we would have no choice but to test the program within an actual device or within the emulator.

Why use Visual Studio?

If I were to give someone the instructions from above and sit the person down in front of Visual Studio instead of SharpDevelop, they would be able to perform all of the steps above with very little variation in the procedure. So, why would one want to pay for Visual Studio if they can use SharpDevelop for free? While there are a number of differences between the two IDEs, the differences that are the most significant here are in design time support and debugging capabilities. When using Visual Studio, the addition of a button to an interface can be done by simply dragging a button from a tool panel onto a simulated screen. The creation of the event handler for that button is initiated by double-clicking on the button. And, in Visual Studio, you can see what the form will look like at design time instead of waiting until runtime to see the results.

The lack of debugging abilities on a remote device are (in my opinion) a significant drawback in using SharpDevelop. As you begin to write more complex programs, the IDE will become less capable of being useful in testing your program. Visual Studio can debug programs that are running within the emulator or on your Windows Mobile device. If you are serious about Windows Mobile development, then you will want to use Visual Studio.

When you are ready to make the switch to Visual Studio, ensure that you get the proper version for the Windows Mobile and the .NET Framework that you wish to target. The Express editions of Visual Studio cannot be used for Mobile development. Given below are the options:

Visual Studio VersionSupported Windows Mobile Versions
Visual Studio .NET 2003Supports .NET Compact Framework 1.0 for Pocket PC 2002 and Windows Mobile 2003
Visual Studio 2005 Standard Edition or better.NET 1.0 and .NET 2.0 from Windows Mobile 2003 to Windows Mobile 6
Visual Studio 2008 Professional.NET 2.0 and 3.5 from Windows Mobile 5 to Windows Mobile 6
Visual Studio Express 2008Does not support any version of Compact Framework or Windows Mobile

Future Edits

If you feel there's an important piece of information that I left out, leave it in the comments area below. Over time, as newer editions of SharpDevelop are released, I expect its capabilities to increase. Some of the limitations of SharpDevelop today may not be limits tomorrow. If you come across a discrepancy as newer versions are released, I'd also appreciate it if a comment is added about these advances.

History

  • 2008 December 18 - Initial publication
  • 2008 December 23 - Added text to emphasize that Visual Studio Express cannot be used.
  • 2009 January 08 - Added links for 2.0 Frameworks.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United States United States
I attended Southern Polytechnic State University and earned a Bachelors of Science in Computer Science and later returned to earn a Masters of Science in Software Engineering. I've largely developed solutions that are based on a mix of Microsoft technologies with open source technologies mixed in. I've got an interest in astronomy and you'll see that interest overflow into some of my code project articles from time to time.



Twitter:@j2inet

Instagram: j2inet


Comments and Discussions

 
QuestionLambda Pin
Esteban Joaquín1-Feb-16 6:32
Esteban Joaquín1-Feb-16 6:32 
GeneralMy vote of 5 Pin
Ondrej_Uzovic10-Aug-12 21:29
Ondrej_Uzovic10-Aug-12 21:29 
GeneralMy Vote of 5 Pin
RaviRanjanKr26-Nov-11 9:51
professionalRaviRanjanKr26-Nov-11 9:51 
GeneralWindows CE 5.0 Development without Visual Studio and Platform Builder Pin
learn2dev4mobi21-Mar-10 8:56
learn2dev4mobi21-Mar-10 8:56 
QuestionIs the SDK installer already included in visual studio 2005 installer cd? Pin
The.Blue.Wizard14-Sep-09 21:22
The.Blue.Wizard14-Sep-09 21:22 
GeneralThanks a lot! Pin
Corinna John6-Sep-09 9:45
Corinna John6-Sep-09 9:45 
GeneralHelloWorldForm in VB net Pin
Member 232260911-Aug-09 3:55
Member 232260911-Aug-09 3:55 
GeneralJust a note about a free debugger for managed code and the Compact Framework Pin
Demetrius Tsitrelis2-Aug-09 12:56
Demetrius Tsitrelis2-Aug-09 12:56 
GeneralRe: Just a note about a free debugger for managed code and the Compact Framework Pin
Joel Ivory Johnson2-Aug-09 14:46
professionalJoel Ivory Johnson2-Aug-09 14:46 
GeneralOr you can always use alternatives, such as Basic4ppc, NSBasic and so on Pin
Ariel zamir27-Jul-09 13:01
Ariel zamir27-Jul-09 13:01 
GeneralSystem.ComponentModel [modified] Pin
JossGP24-Jul-09 3:55
JossGP24-Jul-09 3:55 
GeneralMinimum requirements for WM6 C++ Development Pin
Rotlaus214-Jul-09 20:26
Rotlaus214-Jul-09 20:26 
GeneralRe: Minimum requirements for WM6 C++ Development Pin
Joel Ivory Johnson15-Jul-09 1:52
professionalJoel Ivory Johnson15-Jul-09 1:52 
Generalusing c# dll in smart device application Pin
Mahesh SK12-Jul-09 19:59
professionalMahesh SK12-Jul-09 19:59 
GeneralRe: using c# dll in smart device application Pin
Joel Ivory Johnson13-Jul-09 2:17
professionalJoel Ivory Johnson13-Jul-09 2:17 
GeneralRe: using c# dll in smart device application Pin
Mahesh SK13-Jul-09 14:23
professionalMahesh SK13-Jul-09 14:23 
GeneralA tip that'll save you from huge downloads Pin
sfi8115-May-09 10:05
sfi8115-May-09 10:05 
QuestionDeploying Pin
Alejandro Castañaza26-Mar-09 17:43
professionalAlejandro Castañaza26-Mar-09 17:43 
GeneralWindows Mobile 6 SDK Pin
Griffin Hernandez19-Mar-09 7:30
Griffin Hernandez19-Mar-09 7:30 
GeneralRe: Windows Mobile 6 SDK Pin
Joel Ivory Johnson22-Mar-09 14:08
professionalJoel Ivory Johnson22-Mar-09 14:08 
QuestionRe: Windows Mobile 6 SDK Pin
Wilhelm Berg27-Apr-09 9:01
Wilhelm Berg27-Apr-09 9:01 
AnswerRe: Windows Mobile 6 SDK Pin
anchorage5721-Dec-09 16:07
anchorage5721-Dec-09 16:07 
GeneralRe: Windows Mobile 6 SDK Pin
Joel Ivory Johnson22-Dec-09 2:20
professionalJoel Ivory Johnson22-Dec-09 2:20 
GeneralRe: Windows Mobile 6 SDK Pin
anchorage5722-Dec-09 23:25
anchorage5722-Dec-09 23:25 
Generalvisual GUI designer on #develop Pin
grizli12-Feb-09 4:52
grizli12-Feb-09 4:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.