how to compile code both for .net compact framework and .net frame

G

goodier

Hi,

I have a c# source file which wants to be used for both .net compact
framework and .net framework.
I want to use some kind of #if directive which can choose to compile
different part of code like
#if ABC
..net compact specific
#else
..net framework
#endif

I wonder what is specific condition I can use to indicate it is compiling
for .net compact framework?
 
S

Simon Hart [MVP]

Daniel has written an article on this subject here:
http://www.danielmoth.com/Blog/2004/09/retargetable-256.html

What we often do is target the CF, which enables us to share binary on both
desktop and CF without recompile. The reverse is not true however as it
doesn't work. This does limit you to using the limited CF framework class
library on the desktop which is fine if what you are doing on the desktop is
supported in the CF.

What some other folks do is reuse the source but in different libraries and
use the System.Environment.OSVersion.Platform to determine the OS.

The choice is yours.. :)
 
D

diogoriba

I forgot to mention as Daniel details in another post if using different
libraries, then declare a conditional compilation constant which can be
defined at project level. See here:http://www.danielmoth.com/Blog/2004/09/share-code-if-fullframe_17.html

This is very powerful if targeting different versions of an assembly.

An alternative for using compiler directives to achieve different
results for each platform, you can use partial classes as well:
Have a Class.cs that contains code that is shared by all platforms.
For each platform, have a Class.CF.cs or Class.Desktop.cs that
contains specific functionality. Declare "Class" as partial on all
files.

Now all you have to do is to set up different projects for each
platforms. Each of them will use Class.cs and the platform-specific
implementation of Class. It's pretty practical and useful on big
projects.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top