Most of us are familiar with .NET Framework, .NET Core and .NET Standard applications. .NET Framework is an .NET implementation that supports websites, services apps, and more on windows. But .NET Core is a cross-platform .NET implementation for websites, servers and console apps on Windows, Linux and macOS. And also Xamarin is an .NET implementation which is used to develop cross platform mobile applications.
Moreover, the base libraries for .NET Framework, .NET Core and Xamarin are different. In this blog we’ll see an detailed description of .NET standard. And also we’ll see how we can integrate it with Framework, Core application and Xamarin applications.
What is .NET Standard
It provides us the specification of .NET API’s which are available on all .NET implementations. The aim of .NET Standard is to provide an uniformity across the .NET implementations.
It provides us the following advantages,
- It defines uniform set of BCL API’s that can be used for all .NET implementations, independent of workload.
- It also can be used to produce portable libraries which can be used for all .NET implementations by using the same set of API’s.
- It eliminates or reduces conditional compilation of shared source due to .NET API’s.
.NET implementation support
The following table lists the .NET Standard supported version for various implementations.
If you want to see the live update of this table you can check out this link.
Which version to target?
When you select your library version for your .NET implementation just keep two things in mind.
-
Higher the version, the more API’s available.
-
Lower the version, the more platforms implement it.
However Microsoft recommends to target us the lower version of .NET Standard because it introduces a number of support dependencies.
Creating .NET Standard project using Visual Studio
Install any edition of Visual Studio 2017 from visualstudio.com with any .NET-related workload. To create an .NET Standard follow the below steps:
- In Visual Studio 2017, choose File -> New -> Project, expand the Visual C# > .NET Standard node, select the “Class Library(.NET Standard)” template, give any name to your project, and click OK.
- You can write your business logic into the class library project. In this example, we’ll just create an library project that just return the sum of two numbers.
using System; namespace AdditionOfTwoNumbers { public class AdditionOfTwoNumbers { public int Add(int numberOne, int numberTwo) { return numberOne + numberTwo; } } }
- Right-click on the resulting project file and select Build to make sure the project was created properly. The DLL will be found within the Debug folder (or Release if you build that configuration instead).
4. The respective dll file can be used for both .NET Framework and .NET Core projects.
These are some interesting information’s of .NET Standard. In our next blog we’ll see what are all the new features introduced in .NET Standard 2.0.
Stay tuned for TechMeet360 for more interesting updates.
Happy Coding!
Cheers! 🙂