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.
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?
To solve this problem of code sharing, we can use the following three approaches:
- Create Portable Class Library
- Target Multiple Frameworks ASP.NET Core app
- 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.