Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which Visual Studio 2017 project type to choose for a cross-platform open-source UI-agnostic C# class library and why?

I've got an idea of a C# class library I would like to develop and release to open-source. I would like to make it easily available (with recompilation if necessary) on as many of the available .Net platforms as possible (e.g. full .Net, Mono, .Net Core, Xamarin, only the classic .Net compatibility is a real must, however). The library is not going to depend on anything UI-related nor Windows-only stuff like WPF.

All I need are:

  1. the common .Net types and APIs (I don't want to get surprised by absence of something I consider an essential part of the language)
  2. JSON and XML manipulation facilities
  3. file system access (somewhat restricted perhaps),
  4. HTTPS client,
  5. SQL-level RDBMS client (I don't need ORM functionality though of course don't mind it being available)
  6. Reflection if possible
  7. Async and threading facilities if possible
  8. The latest version of the C# language possible

I am choosing between the following project types

  1. Class Library (.NET Core)
  2. Class Library (.NET Standard)
  3. Class Library (.NET Framework)
  4. Class Library (Portable)

I have heard that Portable is what it says but now we've got Core that runs on Linux and Mac (Windows Phone and Xamarin too perhaps?) and I have almost no problems using EF Core that obviously targets it in my classic Windows Desktop .NET Framework apps. Classic .NET Framework code seems to be quite well supported on non-Windows platforms thanks to Mono and Xamarin. .NET Standard - I have no clue what does this mean, I've just discovered this type with the "New Project" window search tool by looking for all the varieties of "Class Library".

Which one should I choose, why, and what should I know about it?

like image 403
Ivan Avatar asked Mar 11 '17 16:03

Ivan


1 Answers

  • .NET Standard Class Library: Maximum flexibility and should be able to use in all kinds of .NET applications/platforms (evolving, as Unity is not yet covered).
  • .NET Framework Class Library: The old bit you should also know.
  • .NET Core Class Library: Share code among .NET Core apps. It exists, as .NET Standard class library has its limitation (profile surface is usually smaller than .NET Core apps).
  • Portable Class Library (PCL): You can avoid them now, unless you do need to support legacy platforms. Use .NET Standard is better and future proof.

You can easily run a few experiments to assert the statements I made above.

As a library publisher myself, I choose to ship NuGet packages containing .NET Framework version, .NET Standard version, and PCL version at this moment, and would gradually drop .NET Framework and PCL versions in the long run. Many other libraries do the same.

I also wrote a blog post to cover more,

https://blog.lextudio.com/which-class-library-project-to-go-in-visual-studio-2015-2017-a48710cf3dff

like image 170
Lex Li Avatar answered Sep 20 '22 01:09

Lex Li