Search code examples
c#.netnugetcompatibility.net-standard

Which .NET versions should be supported by NuGet packages to maximize their availability and functionality?


TL;DR:

  • Given: I wrote a library with relatively portable functionality (for example, Left.Pad.©.dll). I want to make it available though NuGet.

  • Requirement: If somebody wants to use my library on any version of any platform on any version of any operating system with any updates installed by writing code in any IDE or any code editor, they should be able to do it.

  • Question: What is the minimum set of NuGet target frameworks to achieve that?

  • Bonus question: If there're any "dead" frameworks which shouldn't be targeted, or something else which should be taken into consideration when choosing target frameworks, you can mention it too.


Thoughts (old version):

NuGet packages support multiple .NET Framework versions and profiles, for example, a package can provide net20, net30, net35, net40, net45, sl3, sl4, sl5 etc. versions. However, assuming there aren't always differences in the functionality of a package, providing a lot of versions would be a waste of build time and package size and cause unnecessary complexity. On the other hand, providing a package just for the lowest supported Framework version could cause missing functionality, for example .NET 4 supports in-process side-by-side execution of multiple CLR versions, but previous versions don't, so this feature will be lost if just a version for .NET 3.5 is provided (I'm not sure; I've never used it and don't know the details). If a PCL version is provided, the logic is simple I assume: just exclude versions which PCL covers.


Solution

  • Solution of 2018

    Based on given asnwers and assuming no dependency on platform-specific technologies (like System.Drawing, ASP.NET or WPF; in which case just target the platform you can and be done with it):

    1. netstandard1.0netstandard2.0 Start with .NET Standard 1.0 and go up until you reach maximum functionality.

      This should cover:

      • .NET Framework 4.5
      • .NET Core 1.0
      • Mono 4.6
      • Xamarin.iOS 10.0
      • Xamarin.Android 7.0
      • Windows Universal 10.0
      • Windows non-Universal 8.0 (up to .NET Standard 1.2)
      • Windows Phone 8.1 (up to .NET Standard 1.2)
      • Windows Phone Silverlight 8.0 (up to .NET Standard 1.0)
         

      If you can't reasonably implement the library within the limits of relatively small .NET Standard 1.0–1.2, the last three points are likely to be excluded. If you still need them, see points below.

      .NET Standard 1.5+ increases the requirements on the versions of the frameworks and operating systems, so multi-targeting .NET Standard versions may be required for maximum compatibility.

    2. portable-net40+* The next major point is obsolete PCL. Its .NET Framework 4.5+ versions aren't relevant as they're mostly covered by .NET Standard. If you want to support Windows Phone 8 and non-Universal Windows Store 8, you should do it through PCL, unless you're limited by API, in which case you'll have to add platform-specific targets.

      If you don't need any of additional platforms and .NET Framework 4.0 provides some useful additional functionality over .NET 3.5, you can target it directly, not through PCL.

      This should cover:

      • .NET Framework 4.0
      • Windows non-Universal 8.0
      • Windows Phone 8.0
      • Windows Phone Silverlight 8.0
    3. net20net35 If you want to support ancient desktop Windows versions (like Windows XP) and unupdated more recent Windows versions (like Windows Vista+ with .NET 3.0+), you should add support for desktop .NET Framework targets directly. Note that as of 2018-01-01, the lowest supported .NET is 3.5 SP1, so going lower than that is probably unnecessary and will likely limit API available to you too much with no real benefits.

      This should cover:

      • .NET Framework 2.0-3.5
      • Windows XP
    4. There're other platforms, namely Xamarin-specific ones, Tizen, .NET Micro etc. They can be accessed only by targeting them directly.

      This should cover:

      • Everything else

    TL;DR

    Something like netstandard1.1+portable-net40+win8+net35 covers every relevant platform.

    Solution of the future

    When old .NET versions completely die, only .NET Standard should remain. Well, unless Microsoft invents yet another cross-platform unification technology, like it already did with .NET, .NET PCL, .NET Standard...

    TL;DR

    Use the lowest netstandard you can.