How to write a class library that will work on .NET 3.5 compact framework AND regular framework?

后端 未结 3 1278
慢半拍i
慢半拍i 2021-02-14 13:13

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?

3条回答
  •  抹茶落季
    2021-02-14 14:09

    1. Create a class library for the compact framework.
    2. Add a reference to that library from your .exe project (Desktop or Mobile)
    3. Profit!

    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.

提交回复
热议问题