0

I want to create a library to use in .Net framework applications and Xamarin applications. But there are 3 framework versions:

  • .net core
  • .net framework
  • .net standart

So I could not decide which version to use my common library.

  1. If I create a .net standart library, does it work in .net framework and .net core.
  2. If I create a .net core library, does it work in .net framework and .net standart.

I am confused about frameworks.

1
  • 2
    Maybe this will help Commented Apr 29, 2019 at 6:43

3 Answers 3

3

This might help you decide

  1. .Net Standard : Used for building libraries that can be referenced from all .NET implementations, such as .NET Framework, .NET Core and Xamarin
  2. .Net Core : Used for building cross-platform console apps and ASP.NET Core Web apps and cloud services.

So when if you want your library to be supported by all different type of .Net implementations, .Net standard is the way to go.

Sign up to request clarification or add additional context in comments.

6 Comments

Does the version numbers matter? For example: Does .net standart x vesion supports .net framework y version?
.Net standard have different set of APIs available for each version like .Net standard 2.0 have more APIs than previous versions. Each version is fully supported in .Net framework versions.
@MuhammadHannan: Each version is fully supported in .Net framework versions Aaaaaaaahh, should be careful with that statement. This is so far only true for the currently released .NET Standard versions (1.0-1.6, 2.0). .NET Standard 2.1 will most-likely (no final version released yet, so the decision may change) add API which won't be compatible with any (and probably future) versions of .NET Framework. See Announcing .NET Standard 2.1.
Reason for that is explained in the blog (basically the new Span<T> and more apis come to .NET standard 2.1) and .NET Framework won't implement these as the changes require significant amount of work on the .NET Framework runtime to add support for these due to the high risk of breaking backward compatibility (since .NET framework runs on over a billion machines and doesn't support side-by-side runtimes like .NET Core does)
@Tseng Thanks for mentioning that. That's why I have only mentioned v2.0.
|
2

As you're writing a C# library I imagine you know the difference between a class and an interface. A class is a concrete implementation of some feature set, and an interface defines what features you can expect from an instance that implements it.

Using this as an example, .NET Framework and .NET Core are like classes. .NET Framework is the "classic" implementation, and .NET Core is a newer implementation which has advantages such as being able to run on Linux. If you build a library to target .NET Core or .NET Framework, you are building it to target one of those concrete implementations.

.NET Standard on the other hand is like an interface. Each version of .NET Standard provides a set of features, and different versions of .NET Framework/.NET Core implement different versions of .NET Standard. When you build a library that targets a given version of .NET Standard, you're saying that you can support all of the concrete implementations in the corresponding column of that table.

Deciding what version of .NET Standard to target will depend on what functionality you need to implement your library. More features usually means a higher version and supporting fewer implementations. Fewer features means a lower version and more widespread support.

Comments

1

So many confusing other answers here.

First and foremost it depends on what platforms you are targeting.

  1. is it a generic use library you want share with the world?
  2. is it an application specific library (i.e. reusable code for the same application, i.e. a line of business application) which is to be used on multiple platforms

Case 1

You should go with .NET Standard, since it gives you the most platforms. Which version you use, depends on the features you need.

If you want reach the most platforms, try to target as low as possible (.NET Standard 1.0, it targets .NET Core 1.0, .NET Framework 4.5, Mono, Xamarin iOS 10/Mac 3.0/Android 7.0, UWP 10 and Uniy 2018.1 and all newer versions of these).

You can see the exact .NET Standard Matrix in the provided link.

If you need specific API you have to target a higher version, such as .NET Standard 2.0 which a lot (~22k new APIs from .NET Framework have been ported to .NET Core 2.0 from 1.1) APIs than .NET Standard 1.1.

This may not allow you all APIs (no WPF/WinForm specific apis) but in generic use reusable libraries this shouldn't be an issue.

Case 2

Here, you can also apply Case 1 tips, if possible.

If that doesn't cover your required Apis and you know you don't want target .NET Core or Unity, you can still use the old styled PCLs: Portable Class Library.

They are a more complicated versions of .NET Standard (kinda a predecessor of .NET Standard), where depending on which platform you target the API surface shrinks to only allow APIs to be used which run on all these platforms.

It's not recommended these days to use PCLs, since .NET Standard is preferred and more easy (for library authors) to use and target multiple platforms.

Last but not least, if you really need some feature only on Windows and .NET Framework (or you don't care for .NET Core), you can still cross-target, i.e. have a .NET Standard 2.0 for all platforms and add specific APIs only to net45 target and preprocessor instructions (#if NET45/#endif).

This compiles into two libraries, one for netstandard2.0 and one for net45 (.NET Framework 4.5).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.