How to compile a library in the .NET Framework and the .NET Compact Framework?

I am developing a technical library class that can be used for both types of frameworks (Compact or not).

What is the best way to develop such a library? Using the default .NET functions (for XP Embedded) and making restrictions when using Windows CE (using CF.NET)?

Thanks.

+7
source share
3 answers

I usually approach this with separate DLLs for the game, so I can use the available platform features whenever possible (often not a strict subset / superset, and targeting the intersection is too limited if you want hit performance, etc. )

Most functions are common, so the number of # if-codes (with the feature of assembly symbols) is often minimal.

To avoid the problem of forgetting to add project files, I use a recursive template in csproj, so all .cs files are automatically included.

+4
source

I find that there are two approaches to sharing library classes between .NET and .NET CF code bases.

Code is identical

Often libraries can be identical, especially if they are base libraries that have calculations, or business classes that are identical. For libraries other than the UI, this often happens, since .NET CF is basically a subset of .NET.

In this case, you can simply create a device project and enable it for your project with a full window. You will receive a warning that you are loading a device project, but if you have not used any CF code, this is normal.

The code is very similar but different

In this case, I create two projects and, therefore, two assemblies. I make one of these assemblies the main one and include all the files that are used. In the second, I add files as links to include them as links, so any updates are reflected. Then I use ifdefs for any special cases where they may differ.

+2
source

Consider using preprocessor directives.

You can create 2 versions of the same lib for common .NET and for CF.

Like:

#if (!COMPACT_FRAMEWORK) // some code only for general .NET #endif 
+1
source

All Articles