Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

share code with .net framework project

12 views
Skip to first unread message

Peter Bladh

unread,
Feb 2, 2004, 4:13:08 AM2/2/04
to
Hi

I have one CF solution and one .net framework solution (win32). I'd like to
add a project (the same) to both of the solutions. Some of the code lines
has to be run depending on the platform. I've copied code between projects
before and defined a pre compiler variable for this
#define WIN32

But if the solutions are gonna use the same project (not copying code)
that'll be a problem... Is there a way to workaround this? Is it possible to
define a variable at solution level?

Regards
/Peter Bladh


Ed Kaim [MSFT]

unread,
Feb 2, 2004, 5:54:16 AM2/2/04
to
If I understand your question correctly, you're asking about a good way to
share the same project between two solutions, one targeting the .NET
Framework and one targeting the .NET Compact Framework. If so, then this is
something I do a lot. In the project targeting the full .NET Framework, I
open the Property Pages dialog and add a "Conditional Compilation Constant"
of "DESKTOP" in the "Code Generation" section of the "Build" node in the
"Configuration Properties" folder. Then, wherever I have code that only runs
on the desktop, I surround it with "#if DESKTOP" and "#endif". When I go to
compile, the desktop version compiles everything, whereas the device
versions compiles everything but the stuff inside the DESKTOP directives.
You could do the same for "DEVICE" if you have device-only stuff. Something
like:

#if DESKTOP
Console.WriteLine("On Desktop!");
#else
Console.WriteLine("On Device!");
#endif

"Peter Bladh" <peter...@danahermotion.se> wrote in message
news:OL598yW6...@TK2MSFTNGP09.phx.gbl...

Peter Bladh

unread,
Feb 2, 2004, 9:19:41 AM2/2/04
to
Ok, that works. But I have to remove the line when I work in the CF project,
right? We are several people working in the projects and the shared project
is going to be check in and out of source safe pretty often.

I also have antother related problem. I use a third party component,
Xceed.Zip, and when run on CF I have to set a reference to a different dll
than in the win32 application. How do I do that if I'm gonna share a project
between environments?


/Peter Bladh


"Ed Kaim [MSFT]" <edk...@online.microsoft.com> wrote in message
news:uGxfwrX6...@TK2MSFTNGP09.phx.gbl...

Ed Kaim [MSFT]

unread,
Feb 5, 2004, 11:38:09 PM2/5/04
to
I think I may have left one thing out from my first reply. When I build a
library that will be used between desktop and device, I create two separate
project files that reference the same files. The difference is that one
targets the .NET Framework and has "DESKTOP" set as a compilation constant,
whereas the device one has "DEVICE" defined. This also makes it easy to
reference different versions of components, such as the Xceed.Zip component.

The easiest way to do this is to create a new library project, but then
delete the initial .cs file. Close the project and copy the .csproj to the
main library's directory. Open the project and add all the files to it so it
reflects the original project. Now you'll have a directory with all the
source files, including a desktop project file and a device project file.
Developers can work from either project, and their changes will show up in
the other (because it's actually the same set of source files).

The downside to this method is that it requires developers to keep both
projects up-to-date when they add or delete a file.

I'm sorry I don't have a better solution, but I hope this works for you. It
works well for me, but I usually work on small projects at a recreational
level, so your mileage may vary. Maybe someone else has a better solution.

"Peter Bladh" <peter...@danahermotion.se> wrote in message

news:%23LSmPeZ...@TK2MSFTNGP09.phx.gbl...

Ed Kaim [MSFT]

unread,
Feb 5, 2004, 11:43:35 PM2/5/04
to
There is an article that covers this a little more clearly at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/customctrlscompactfx.asp.
It's in the context of building controls for both desktop and device.

"Ed Kaim [MSFT]" <edk...@online.microsoft.com> wrote in message

news:OFVmIsG7...@TK2MSFTNGP11.phx.gbl...

Mark Johnson

unread,
Feb 6, 2004, 8:15:57 AM2/6/04
to
Yes, I do something similer, only I use "COMPACT" in the Compact project
with nothing set in the DESKTOP project:

#if (DEBUG && !COMPACT)
#warning Net.Framework Desktop (Debug) is defined
#elif (!DEBUG && !COMPACT)
#warning Net.Framework Desktop (Release) is defined
#elif (DEBUG && COMPACT)
#warning Net.Framework.Compact (Debug) is defined
#else
#warning Net.Framework.Compact (Release) is defined
#endif

With this you can use the #else saving the second #if

#if (!COMPACT)
#if (ODBC)
#warning Reference to Microsoft.Data.Odbc.dll needed
using Microsoft.Data.Odbc;
#endif
#warning Reference to Interop.ADOX.dll needed
using System.Data.OleDb;
using System.Data.SqlClient;
#else
using System.Data.SqlServerCe;
#endif

Mark Johnson, Berlin Germany
mj1...@mj10777.de


"Ed Kaim [MSFT]" <edk...@online.microsoft.com> schrieb im Newsbeitrag
news:OFVmIsG7...@TK2MSFTNGP11.phx.gbl...

Peter Bladh

unread,
Feb 6, 2004, 9:26:53 AM2/6/04
to
Thanks, I'll try that!

/peter

"Ed Kaim [MSFT]" <edk...@online.microsoft.com> wrote in message

news:OFVmIsG7...@TK2MSFTNGP11.phx.gbl...

0 new messages