简体   繁体   中英

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

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.

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM