How do I write a .NET class library that I can recompile for either the regular .NET 3.5 Framework, or the .NET 3.5 Compact Framework?
R – How to write a class library that will work on .NET 3.5 compact framework AND regular framework
compact-frameworknet
Related Topic
- C# – Deep cloning objects
- .net – How to detect what .NET Framework versions and service packs are installed
- C# – What are the correct version numbers for C#
- .net – the best algorithm for overriding GetHashCode
- C# – Path.Combine for URLs
- C# – How to get a consistent byte representation of strings in C# without manually specifying an encoding
- Scala: list.flatten: no implicit argument matching parameter type (Any) = > Iterable[Any] was found
- .net – the difference between .NET Core and .NET Standard Class Library project types
Best Answer
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: