Search code examples
.netmono

.NET 5 and Mono


.NET 5 is being touted as a complete unification of the .NET Core and the .NET Framework that will run on Mac, Windows and Linux.

Mono is a reimplementation of the .NET Framework to allow .NET applications to run on Linux.

As such, is it fair to assume that Mono will essentially become obsoleted and only needed for legacy applications once .NET 5 is widely used for new developments or are there some things that it would still be needed for?


Solution

  • I would answer the question this way...

    The .NET Framework was written by Microsoft and they have released many versions of it ( currently at 4.8 ).

    There are lots of ways to think about the .NET technology stack but, for this post, .NET contains the following components:

    • A compiler suite ( C#, F#, VisualBasic .NET )
    • the Base Class Libraries ( BCL )
    • the runtime ( the bits needed to execute the compiled CIL )

    The Mono project was created to implement a fully Open Source .NET Framework clone.

    Initially, Mono implemented all of the above itself. For example, there is a Mono native C# compiler ( mcs ), a Mono implementation of ASP.NET, and even a Mono implementation of Windows Forms. Over time, Microsoft began releasing stuff as Open Source. Mono began incorporating this and so Microsoft .NET and Mono started to share a lot of code in common ( eg. the Roslyn C# and VB.NET compilers, ASP.NET MVC and the DLR ). Even some of the BCL code was opened up and shared between Mono and .NET. Not the runtime though.

    Some of the contributors to the Mono Project formed a company, Xamarin, with the goal of using Mono to create applications for mobile operating systems like iOS and Android. They enhanced and re-used the Mono runtime ( adding a sophisticated Ahead-of-Time compiler for example ). They also re-used the Mono BCL although some parts of the BCL could not be used and new APIs were added for platform specific elements, especially GUI stuff. A "cross-platform" mobile GUI API was created as well ( called Xamarin Forms ). So while Microsoft .NET remained Windows only, Mono could be used to create applications for Mac, Linux, Windows, iOS, Android, and others.

    More recently, Microsoft created their own parallel re-imagining of the .NET ecosystem. They called this new version .NET Core. Like Mono, .NET Core was Open Source and multi-platform. To differentiate the two Microsoft implementations, the original .NET was re-named to .NET Full Framework or just .NET Framework. While .NET Framework continues to be Windows only, .NET Core allows applications to run on Windows, MacOS, and Linux.

    .NET Core shares a lot with .NET Full Framework. Like Mono, .NET core uses the Roslyn compiler suite for example. The BCL however was new ( partially incompatible with .NET Full Framework ). The runtime was totally new ( using RyuJIT for example ).

    .NET Core did not "replace" .NET Full Framework. For example, Windows Forms and Windows Presentation Foundation ( WPF ) applications cannot be created with .NET Core.

    The Mono Project ( eg. the most recent 6.12 release ) remains a clone of .NET Full Framework and, even where it has taken code from .NET Core, the goal remains .NET Framework compatibility.

    So .NET found itself with multiple implementations: .NET Framework, .NET Core, Mono, and Xamarin. All of these versions were very similar but incompatible to some degree. Microsoft tried to address this by creating the idea of ".NET Standard" with the aim of specifying a shared subset of features that could be expected to execute on any of the above .NET versions.

    In fact, there is kind of another branch of .NET now in that Microsoft created something called Blazor which compiles .NET applications to web assembly ( WASM ). Blazor uses the Mono / Xamarin runtime.

    As another level of confusion, the .NET Core initiative produced some bits that can run on either .NET Core or .NET Full Framework. For example, ASP.NET Core is a re-imagining of ASP.NET MVC. ASP.NET Core is the only version of ASP.NET on .NET Core but both Mono and .NET Framework developers can choose from ASP.NET Web Forms, ASP.NET MVC, or ASP.NET Core. Outside of ASP.NET Core itself though, the BCL between .NET Core and .NET Framework is different and so it is quite possible to create an ASP.NET Core application that will not run on .NET Core. There is also Entity Framework Core with a similar story.

    All and all, while a fantastic bucket of tech, the jumble of versions and what works with what has become a complete mess.

    .NET 5 and .NET 6 (note the drop of the term "Core" in the name) are an attempt to unify and massively simplify all of the above.

    By most meaningful measures, .NET 5 is a continuation of .NET Core and you could think of .NET 5 as the most recent .NET Core release. Unlike .NET Core though, it is not considered an "alternative" implementation to .NET Full Framework. Rather, it is the future for both .NET Core and .NET Full Framework. There will not be another .NET Core ( by name ) or .NET Full Framework release. Microsoft dropped "Core" from the name to signify that there is meant to be only one .NET and also skipped version 4 ( of .NET Core ) to stress that version 5 is the upgrade path for both .NET Core 3.1 and .NET Framework 4.8.

    As .NET 5 is meant to replace .NET Framework, it includes things .NET Core did not like the ability to create Windows Forms and WPF applications. With .NET 5, developers will now use the same BCL for both a WPF app and a web app ( where before .NET Framework and .NET Core had different versions of the BCL ). In .NET 5, there is only one version of ASP.NET ( ASP.NET Core ).

    Sadly, Microsoft was not able to finish the job of unification and, with .NET 5, you still require Xamarin ( and Mono ) to create applications for mobile operating systems like iOS and Android. This means that you still need .NET Standard as well to write code that can run on both.

    The goal for .NET 6 is to bring Xamarin into the fold. To do this, .NET 6 will contain two different run-times: the one from .NET Core ( eg. RyuJIT ) and the one from Mono ( eg. MonoJIT ).

    Going back to our list above, we said that .NET was a few things:

    • A compiler suite ( C#, F#, VisualBasic .NET )
    • the Base Class Libraries ( BCL )
    • the runtime ( the bits needed to execute the compiled CIL )

    In .NET 6, you use the same compilers regardless of your target ( Linux, Windows, MacOS, iOS, Android, Blazor / WASM, etc ). Importantly, you also use the exact same BCL. A new cross-platform GUI API has even been envisioned to replace Xamarin Forms ( MAUI ) which will work across all targets. So, to a developer, .NET 6 looks the same no matter what you are building. This means that you do not need ".NET Standard" anymore. With .NET 6, there is only one .NET version ( that is not legacy ).

    However, their are still two run-times in .NET 6: the .NET Core one and the one from Mono / Xamarin. Windows, Linux, and MacOS will use the .NET Core runtime to execute .NET Code. On iOS, Android, and WASM, .NET applications will run on the Mono run-time. Mono lives on in .NET 6 but it is only the runtime. The Mono BCL is legacy because the .NET Full Framework BCL is legacy.

    So, the question "is it fair to assume that Mono will essentially become obsoleted" has two answers:

    1 - Mono is not going anywhere. In fact, it is ( incredibly ) going to be part of the official .NET release from Microsoft in .NET 6 and beyond. That is, the Mono run-time is a core part of .NET 6.

    2 - The full Mono Project release ( most recently version 6.12 ) is legacy as it mimics .NET Full Framework and its now legacy BCL ( eg. the old ASP.NET design -- including Web Forms ).

    Microsoft has copied the Mono runtime into a different GitHub repository ( outside of the GitHub projects managed by the Mono Project ). To my knowledge, all official development is done in the Microsoft repository. As it is still Open Source however, the code can be incorporated into the Mono Project projects as well.

    I have no idea what the future plans for the Mono Project are independent of the Mono runtime that is now maintained by Microsoft. As of this writing, the Mono projects at GitHub remain very active.