如何编写可以为常规.NET 3.5 Framework或.NET 3.5 Compact Framework重新编译的.NET类库?
The two frameworks aren't binary compatible*, unfortunately, but don't let that stop you.
Create two projects in your solution (one normal Class Library project, and one Compact Framework Class Library project), and add all the files from one project to the other as links by clicking "Add|Existing File" and then checking the "add as link" checkbox on the file dialog.
Now you only have one set of source code to maintain, but your solution will build both DLLs at the same time.
If you have any code inside a file that's specific to the desktop framework and won't work on the compact framework, you can wrap it in a compiler directive (at least in C#) like this:
#if PocketPC
// mobile-specific stuff here
#else
// desktop-specific stuff here
#endif
> The two frameworks aren't binary compatible >
Actually the Desktop version can load and run CF assemblies.
Seriously, I don't know why the top answer is so top. You don't need two separate projects at all. Also i'm not in love with pre-processor directives, they're ugly and require additional knowledge about the project when playing with the build parameters. It is much more pretty to outsource all the incompatible bits and pieces to an interface (IPlaformServices or such like) or you could even just ask:
if(Environment.OSVersion.Platform == PlatformID.WinCE)
{
// winCE specific
}
else
{
// desktop specific
}
Both of these are better solutions than preprocessor directives IMO.
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.