Sharing code between Smart Device Project and desktop project

D

Dan

I'd like to have a set of more-or-less common code which I want to use for
both desktop and smart device projects. I have two questions:

1. How can I set up conditional compile directives for those parts of the
code which are different on desktop and smart device projects
2. How can I actually share the same .cs source code files between the two
projects. If I try to open a smart device project and add the files which
are in the desktop project's directory, those files get copied into the
smart device project's directory. Thus, changes which I make in one project
don't get applied to the other one. On the other hand, if I define the
smart device project in the same directory as the desktop project, I
overwrite files in the desktop project directory (in particular
AssemblyInfo.cs-- I can rename the output files to distinguish between the
assemblies for the two projects).

Thanks...

Dan
 
L

lukasz

1. Add your own directive in the projects' properties (add "SMARTDEVICE"
after "DEBUG, TRACE"). Then in code use:

#if SMARTDEVICE
....
#else
....
#endif


2. Make two solutions: YourAppDesktop & YourAppDevice. To one solution
(arbitrary) add new library project YourAppLibrary which will contain the
shared files; it'll be compiled to a DLL. The to the other solution add an
EXISTING project: YourAppLibrary. Now, assuming you have added main projects
to both solutions (say, YourAppProjectDesktop & YourAppProjectDevice),
choose the projects' nodes, then subnode References, and add new reference.
Choose 3rd tab, choose YourAppLibrary.

Summarizing:
YourAppDesktop solution
YourAppLibrary (new)
YourAppProjectDesktop
reference to YourAppLibrary (not DLL, but project)
YourAppDevice solution
YourAppLibrary (existing, from Desktop's solution)
YourAppProjectDevice
reference to YourAppLibrary (not DLL, but project)

The disadvantage is both solutions now need a DLL, but I don't know of an
other method to share sources.
 
D

Dan

Thanks for the conditional compile advice. However, I think there's a
problem with answer 2: "YourAppLibrary" also will need to be compiled as
both a Desktop and SmartDevice DLL, otherwise it doesn't run properly on the
smartdevice (at least that's been my experience).

Dan
 
C

Chris Tacke, eMVP

Right. Instead runtime checks should be done. A static constructor to
check the current OS is the simplest method, then all methods can be
redirected based on that check.

-Chris
 
L

lukasz

I haven't done any smart device project so I weren't aware of the problem,
though it makes sense since it uses a different framework (CF). See if you
can batch build the shared DLL for both desktop Framework & CF (Build |
Batch Build), or whether a macro would allow you to choose compilation
framework depending on active project.
 
R

r_z_aret

I use eVC 3, eVC 4, and VC 6 with the same source code. I suspect you
are using VS.NET for "big" Windows (desktop) and CE, so I'm not sure
how relevant my experience will be. But see details below.

I'd like to have a set of more-or-less common code which I want to use for
both desktop and smart device projects. I have two questions:

1. How can I set up conditional compile directives for those parts of the
code which are different on desktop and smart device projects

I suggest checking a thread called "Compiler Directive" in
microsoft.public.pocketpc.developer around 1 April 2004

2. How can I actually share the same .cs source code files between the two
projects. If I try to open a smart device project and add the files which
are in the desktop project's directory, those files get copied into the
smart device project's directory. Thus, changes which I make in one project
don't get applied to the other one. On the other hand, if I define the
smart device project in the same directory as the desktop project, I
overwrite files in the desktop project directory (in particular
AssemblyInfo.cs-- I can rename the output files to distinguish between the
assemblies for the two projects).

I use eVC 3, eVC 4, and VC 6 with the same source code. Project->Add
Files has never copied files over when I've used it. I do need to put
the eVC 3 and eVC 4 workspace/project files (.vcw, .vcp, etc.) in
separate directories so _they_ don't overwrite each other. For eVC 3
and eVC 4, I define a workspace (.vcw) for each of my programs, and
then a separate project (.vcp) for each platform (SDK). Each of those
projects sends its output to a different place.
The following is a _crude_ diagram:
program main - shared source code
desktop
x86rel - output for release builds for x86 ("big" Windows)
x86dbg - output for debug builds for x86
Pocket PC
mipsrel - output for release builds for MIPS (Pocket PC)
mipsdbg - output for debug builds for MIPS (Pocket PC)
... etc.

Thanks...

Dan

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret, eMVP
PenFact, Inc.
500 Harrison Ave., Suite 3R
Boston, MA 02118
www.penfact.com
 
D

Dan

Chris--

Thanks very much, but I'm not sure that follow. Are you saying that I can
compile a library against the desktop framework and then run that library on
a smart device, as long as I check the OS for those methods which are
implemented differently on the SmartDevice?

Dan
 
N

Nick Hoggard

2. How can I actually share the same .cs source code files between the two
projects. If I try to open a smart device project and add the files which
are in the desktop project's directory, those files get copied into the
smart device project's directory. Thus, changes which I make in one
project
don't get applied to the other one. On the other hand, if I define the
smart device project in the same directory as the desktop project, I
overwrite files in the desktop project directory (in particular
AssemblyInfo.cs-- I can rename the output files to distinguish between the
assemblies for the two projects).

Make sure that your 'shared' code is created as a .NET CF library, rather
than a full framework library. Then extend that assembly with another one
that contains your full framework specific code.

The full framework can ran a .NET CF library as it is merely a sub set of
the full framework, but not the other way around.

Nick
 

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