Code Sharing in .NET Core

With .NET Core, we can currently develop applications with three different .NET frameworks for different platforms. The traditional or standard .NET Framework is for Windows, Mono framework for iOS, OSx and Android and .NET Core for Windows, Mac and Linux.

.NET Frameworks

These frameworks use different framework class libraries. It means code written in one framework cannot be used with other frameworks. For example, a console application developed with .NET Framework cannot run on .NET Core or vice-versa. Thus, code-sharing is not allowed.

It would be nice to write code once and share with other applications with different .NET frameworks. Isn't it?

Code Sharing

To solve this problem of code sharing, we can use the following three approaches:

  1. Create Portable Class Library
  2. Target Multiple Frameworks ASP.NET Core app
  3. Target .NET Standard

Creating portable class library to share code with other .NET frameworks is not a new thing in .NET. Learn about it here.

Learn about how to target multiple frameworks in ASP.NET Core application for code sharing in the next chapter.

Want to check how much you know ASP.NET Core?