C# library for .NET Core and .NET Framework

2019-06-11 00:32发布

问题:

I'm doing a Network library (https://github.com/Eastrall/Ether.Network) for now targeting the .NET Core framework, but I want support both .NET Core and .NET Framework (4.*)

I heard about adding some lines on the project.json is this a good solution?

Can someone help me with this? Thanks

回答1:

Yes, modifying project.json is what you need. It should look like:

{
  "version": "1.0.0",

  "dependencies": {
    "NETStandard.Library": "1.6.0"
  },

  "frameworks": {
    "netstandard1.3": {
      "imports": "dnxcore50"
    }
  }
}

Here is a scheme of mapping the .NET Platform Standard to platforms of interest from the official documentation:

A few quick notes:

  • If a library targets .NET Platform Standard version 1.3, it can only run on .NET Framework 4.6 or later, .NET Core, Universal Windows Platform 10 (UWP), and Mono/Xamarin platforms.
  • If a library targets .NET Platform Standard version 1.3, it can consume libraries from all previous .NET Platform Standard versions (1.2, 1.1, 1.0).
  • The earliest .NET Framework to support a .NET Platform Standard version is .NET Framework 4.5. This is because the new portable API surface area (aka System.Runtime based surface area) that is used as the foundation for the .NET Platform Standard only became available in that version of .NET Framework. Targeting .NET Framework <= 4.0 requires multi-targeting.

For further details it is recommended to check out the official documentation.