How to compile a library on .NET Framework & .NET Compact Framework?
Asked Answered
I

3

7

I'm developing a technical library class that can be used on both types of Frameworks (Compact or not).

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

Thanks.

Istanbul answered 27/12, 2010 at 9:2 Comment(0)
P
4

I usually approach this by having separate dlls per playform, so I can use available platform features when possible (often neither is a strict subset/superset, and aiming for the intersection is overly limiting if you want the beat performance etc).

Most features are common though, so the amount of #if code (with feature-specific build symbols) is often minimal.

To avoid issues with forgetting to add project files, I use a recursive wildcard in the csproj, so all .cs files are included automatically.

Phanerogam answered 27/12, 2010 at 9:11 Comment(3)
That means that you have two distinct projects (one .NET & one CF.NET), both including same source file but just the project type is changing? So, when you modify one project, both will automatically be modified?Istanbul
Thanks for explanation :), I'll essentially distinguish both framework because of device & battery management... (Easier in .NET that CF.NET)Istanbul
Visual studio makes it a pain to create two project files in the same folder; did you find an easy way to do that? It sounds like you "roll your own" project file... I wonder how you do that...Declivitous
T
2

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

The Code is Identical

Often the libraries can be identical, particularly if they are basic libraries that have calculations, or business classes that are identical. For non-UI libraries this is often the case since .NET CF is mostly a subset of .NET.

In this case, you can just build a device project and include it for your full windows project. You will get a warning that you are loading a device project, but if you haven't used any CF specific code, it is fine.

The Code is Very Similar, but Different

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

Toneme answered 30/12, 2010 at 21:32 Comment(2)
In my case, it's a technical library (little framework) that embed API of all devices it should turn on. But all this devices haven't the same OS version (some are on WinCE, others on WinMobile, others on XP Embedded) and the battery management is different in some case, that's why I've asked the question. Only things that change is the way to check the power state of the device, so, for you, what would be the best solution? Thanks for reply.Istanbul
First, the OS version shouldn't matter much since .NET isolates it, so all the basic stuff will work. I would probably build one assembly for CE/WM as a CE 5.0 library, and another for XP embedded. Then share the code and ifdefs any differences.Toneme
G
1

Consider using preprocessor directives.

You can build 2 versions of the same lib for general .NET and for CF.

Like :

#if (!COMPACT_FRAMEWORK)
            // some code only for general .NET 
#endif
Gilgilba answered 27/12, 2010 at 9:10 Comment(3)
Yes but by default, should be the project a Windows project (.NET FW) or a Smart device project (CF.NET FW) ?Istanbul
Yes, but when creating you first choose the project type you will use (Smart or Windows one). ;)Istanbul
The end result is dll, so must be no difference. And as I know there is no differentiation on win/smart device class lib templates.Gilgilba

© 2022 - 2024 — McMap. All rights reserved.