views:

1723

answers:

5

I have a goal to build an application with UI that would run on both Windows Mobile and "normal" desktop Windows. The priority is for it to "look good" under Windows Mobile, and for desktop Windows it is OK if it distorted. Before I invest days trying, I would like to hear if that is possible to begin with. There are several parts to this question:

  1. Is .NET Compact Framework a subset of "normal" (please, edit) .NET Framework? If not, does MSDN have any information anywhere on classes that are in .NET Compact Framework, but not in "normal" (again, please, edit) framework?

  2. Is behavior of shared classes same in both frameworks?

  3. Is it possible to have a single Visual Studio 2005 solution / project for both platforms? If yes, how do to set it up?

  4. Any other comments and advice? Any relevant links?

+1  A: 

CF, in general contains a subset of the classes from the regular framework - but you can't directly execute code from one on t'other. Additionally, rather than just being a subset, there are probably a few things in compact that aren't in the regular version, such as the GUI things specific for mobile devices (soft keys, etc) - assuming you are writing a winform exe, and not a web page (which might be the simplest way to get compatibility).

With some effort, it it possible to share logic code, in particular utility dlls - but they need different csproj files (since they have completely different compile-time "targets"). To reduce maintenance, you can often cheat by hacking the csproj to use wildcards, like from here:

<ItemGroup>
  <Compile Include="..\protobuf-net\**\*.cs" />
</ItemGroup>

For UI, things get a lot tricker. In general the expectation would be to have shared business logic and separate UI for different target devices.

Marc Gravell
The business logic is written in pure C, and can be recompiled for any platform imaginable. The point is to have a single UI for both Windows and Windows Mobile to reduce maintenance.
Ignas Limanauskas
CF assemblies are retargetable, so if you have one that doesn't directly reference any device stuff, it will run as-is on the desktop - no recompiling at all. Admittedly, having something that meets the criteria to noth throw a missingmethodexception is rare, though.
ctacke
+1  A: 

1). There is a Compact Framework so yes; And it is a subset of the full .NET framework. I've got a poster on my wall at the office that denotes a whole bunch of classes that work in CF... I don't recall off the top of my head if there are any that are purely CF, but I suppose there must be some. There are a couple of good books on the subject - one by Paul Yao that I have and another by Andy Wigley - both are available on Amazon.

2). As far as I'm aware, the classes that are CF and full framework work the same but need to be compiled for different targets.

3). I would hazard a guess that providing you only use classes that are common to both, that you could use the same solution, I don't know the extent you would have to go to make it compile for the compact device and the full version though, nor can I say with complete certainty that it can be done. I'd hazard a guess that the process isn't simple.

4). Go to your local book store and have a flick through those two books I mentioned. Like I said, I have the one by Paul Yao and it seems to cover most of what I could imagine needing on a compact device.

BenAlabaster
Do you have an affiliate thingy with Amazon? If I bought the book(s) some pennies might fall on you :)
Ignas Limanauskas
Sadly I don't. Consider it a freebie and my bit to give back to the programming community...
BenAlabaster
+3  A: 

Hello! Nice multi-part question:

  1. Differences between the Full Framework and the Compact Framework
  2. The article above has links to relevant documentation about how class behavior differs (it definitely DOES differ in some situations)
  3. Very simple! Create a single solution with a set of base functionality in a Class Library, then create two client projects (one for your desktop app and one for the windows mobile app). Finally, add references to the class library to both client projects.
  4. Depending on the breadth of the project you are working on, you may want to check out the Model View Controller pattern. It may be a bit much for your project, but if you want to share UI behavior between projects, it can be a life saver.

Hope that helps!

Zachary Yates
Thanks, vote up if you liked it! ;)
Ignas Limanauskas
+5  A: 

P.S. I found the poster online - it'll show you all the classes that are CF. I ordered it fro Microsoft because Kinkos wanted $65 to print it out in color for me! Microsoft sent me a couple of copies free - all I had to do was ask:

http://www.microsoft.com/downloads/details.aspx?familyid=7B645F3A-6D22-4548-A0D8-C2A27E1917F8&amp;displaylang=en

I have it hanging in my cubicle and it's a godsend when trying to remember which namespaces classes can be found in.

BenAlabaster
+7  A: 
  1. The CF contains a subset of the full framework (FFx), but it is not a pure subset. There are actually several things available in the CF that aren't in the FFx, which makes it a bit more difficult. CF apps also, except in the most rudimentary cases, use P/Invoke. Those calls are never the same from the desktop to the device, so they are not directly portable (though with a little abstraction you can have a platform-agnostic interface).
  2. For the most part, behavior is the same. I've seen some cases where it's not, and I recall some event ordering not always being identical though, so trust but verify.
  3. It's possible through very careful massaging of the configurations, but I certainly don't recommend it. It's difficult to maintain and very fragile. Instead have two project files, one for CF and one for FFx. You're likely to have code file differences anyway. Add the code files as links to each project so they both use the same physical source file. I'd recommend using some form of CI to help ensure they both build at all times.
  4. Take a look at Dan Moth's MSDN article and blog entries on sharing code assets.
ctacke
Great links, thanks! I would not have found myself.
Ignas Limanauskas
The link to the Dan Moth's article solves my problem. Thanks!
Ignas Limanauskas