If you are working as a developer and want to switch to the .NET world, you will need to know what are possibilities for you inside. As .NET Framework is the most popular technology from .NET Ecosystem you can use it to build different kinds of applications, but these days, there are some new things, like .NET Core and .NET Standard library. Is this something we can use in a project or build?
There is some confusion when trying to use specific tech stack in the .NET ecosystem, as there are so many options, such as which type of runtime should you use? In this text we will try to make all of these points clear.
In general, .NET is an open source developer platform, created by Microsoft, for building many different types of applications, such as: web, mobile, desktop, games, etc. It consists of different tools, programming languages and libraries. Lets start with a brief history of the .NET.
The history behind .NET
During 1990s, Microsoft started to work on something called .NET Strategy. The key point of this strategy was to encompass all Microsoft products and add .NET to existing product names. In the 2000s, .NET framework was known as the Next Generation Windows Services (NGWS). First beta versions of .NET framework were released in the late 2000s and the first version .NET 1.0 was released on February 13, 2002. Since then many versions were released with new features. Some of the most important were:
- .NET Framework 2.0 (November 2005.): generic collections, iterators, nullable types, etc.
- .NET Framework 3.0 (November 2006.): WPF, WCF and WWF.
- .NET Framework 3.5 (November 2007.): AJAX, LINQ, ASP.NET MVC.
- .NET Framework 4.0 (April 2010.): MEF, DLR, task parallel library, Razor view engine, new C#/VB language features.
- .NET Framework 4.5 (August 2012.): support for Async, zip compression support.
- .NET Core 1.0 (November, 2014.): first version which included cross-platform support. ASP.NET 5 and .NET Native.
- .NET Core 2.0 (August 2017.): the second version, with major performance improvements and implemented .NET Standard 2.0.
- .NET Framework 4.8 (April 2019.): final version included JIT enhancements, High DPI enhancements for WPF applications, accessibility improvements, performance updates, and security enhancements.
- .NET Core 3.0 (September 2019.): performance improvements, C# 8.0 new features, implements .NET Standard 2.1. Windows Desktop supports .NET Core for Windows Forms and WPF.
The image below shows timeline of .NET main events:
.NET Ecosystem: An overview
Currently, in 2020. .NET Ecosystem consists of different components in the development platform. It encompasses different runtimes, such as:
- .NET Framework (WPF, Windows Forms, ASP.NET) - Windows centric.
- .NET Core (ASP.NET Core, Universal Windows Platform - UWP) - Cross-platform, works side-by-side with other versions.
- Mono for Xamarin (IOS, OS X, Android) - Cross-platform.
All of the above runtimes implement .NET Standard Library, which is a specification of .NET APIs that have implementations for each runtime. So that code that is created for one runtime, can be executed with other runtime.
All the runtimes uses tools and infrastructure to compile and run code. This includes languages (C#, Visual Basic), compilers (Roslyn), garbage collection, as well as build tools like MS Build, or (Core) CLR.
In this section we will look at main .NET runtimes. We consider .NET runtime as anything that implements ECMA-335 Standard for .NET.
.NET Framework and .NET Core can be downloaded from the official Microsoft site. LTS (Long-term support) versions have extended support period and should be used.
.NET Framework is a software development framework for building and running applications on Windows. It is party open-sourced at here. .NET Framework consists of Common Language Runtime (CLR), .NET Framework Class library and Application workloads (WPF, Windows Forms and ASP.NET). CLR is part of common infrastructure than run code, jit, do garbage collection (C#, VB.NET, F#), etc. Code that is managed by CLR is called managed code. Code is compiled into Common Intermediate Language (CIL) and stored in assemblies (with .exe or .dll extension). When application runs, CLR takes assembly and uses just-in-time compiler (JIT) to transpile machine code into code that can run on specific computer architecture.
.NET framework library contains classes, interfaces and values types that provides capatibilites, such as string, file system support, etc. It allows creating different type of applications, such as: console applications or Windows Forms, Windows Communication Foundation (WCF), Windows Workflow Foundation (WF), Windows Presentation Foundation (WPF), ASP.NET (Forms, Web API), Azure (WebJobs, Cloud Services). Most of those are specific to Windows platforms and use Windows API, so they work only on Windows platform.
If you want to run applications that are built by using .NET Framework you need to install it first, although Windows already comes with some versions installed. Each version have CLR and library. It is possible to install multiple versions, side by side (only major versions). Minor versions will override existing versions, as they don’t contain braking changes. For example for .NET 4.2.3: major version is 4 (new CLR), 2 minor version means (new library, which introduces new features) and 3 revision (bug fixes).
.NET Framework is installed usually at C:\Windows\Microsoft.NET\Framework (or Framework64). Inside, you will find folders with all major versions installed.
.NET Core is one of runtimes in .NET Ecosystem. It is released in 2016. and its open-sourced (https://github.com/dotnet/core). It does not represent a new version of .NET Framework and will not replace it. Its completely independent version, which is build to allow cross-platform capatibility to application development. .NET Core consists of App Host (dotnet.exe) that run CLR and Library. It has Common language runtime (CoreCLR) and .NET Core Class Library.
CoreCLR uses JIT Compilation and garbage collection to run code. It supports C#, VB.NET and F#. .NET Core has .NET Core Class Library, which includes classes that provides different capatibilities and its a smaller subset of .NET Framework library. It supports different types of application workloads, such as ASP.NET Core (MVC and API), console applications and UWP (currently). UWP provides a common type system, APIs, and application model for all devices running on Windows 10. From the .NET Core 3.0 SDK it includes support for Windows Forms applications, including Windows Forms Designer.
.NET Core can run on different platforms: Windows Client, Server, IoT, Linux, Ubnutu, FreeBSD, Tizen, Mac OSX and can be installed side-by-side of different versions, per machine or user.
.NET Core is installed in C:\Program Files\dotnet\shared\ Microsoft.NETCore.App[versions], which live side by side.
In addition, its possible to create self-contained version, which don’t need installed .NET core on the host machine, as it packs app host in the resulting .exe file. The disadvantage is that the the deployment will be larger. It is run via:
dotnet publish -r linux-x64 --self-contained
Mono For Xamarin
Mono is a clone of .NET framework runtime. Mono is created in 2001., but part for Xamarin is released in 2011. and its open source: https://github.com/mono/mono and www.mono-project.com. Microsoft acquired Xamarin in 2016., making it a fully open-source branch of the .NET platform. It consists of Mono runtime and Xamarin Class Library and can run application workloads like IOS, OS X and Android.
Mono is similar to .NET Core and includes Garbage collection, JIT, AOT and full support for C# (not VB.NET and F#). The Mono AOT compiler enables .NET code to be built into a single native code executable that can run on a machine, much like C++ code. Mono for Xamarin has a class library that support creating applications (for IO, collections, etc). But its a subset of .NET framework, there are not all components supported.
It can run following workloads: Apple IOS applications, MAC OS X applications (desktop), Android applications, etc. and allows you to share code between these platforms and they run as native applications on devices that run on Mono. Each application is bundled with the Mono runtime and a class library. There is no need to install Mono on a device.
Over time it branched out into wider areas, such as game development, where Unity and Mono for Xamarin have long worked together to provide C# support in Unity.
Other frameworks: .NET Compact Framework & .NET Micro Framework
These are specific frameworks with a specific purpose. Both runtime were attempts to provide cut-down runtimes that would run on more constrained devices, such as PDAs, mobile phones factory controllers, etc. For example, .NET Micro Framework was build for resource-constrained devices with at least 256KB of flash and 64KB of RAM memory.
Silverlight was a popular cross-platform, .NET technology that enabled building rich media experiences for browsers. It was released on 2007 and had multiple capatibilites such as playing videos, download medias, creating rich UI and animations, etc. In 2015. Microsoft decided to stop supporting Silverlight in October 2021.
Besides Microsoft official runtimes, there are .NET runtimes made by community, such as DotGNU Portable.NET, DotNetAnywhere, CosmosOS and CrossNet. All of them have a slighty different approach to build such a framework.
As different runtimes uses different class libraries, e.g., .NET Framework uses .NET Framework class library, while .NET Core contains its own class library, as well as Xamarin with its own class library. In this way its hard to share code between different runtimes, as they don’t use the same APIs. Microsoft solution to this is .NET Standard library, released in 2016. It represent set of (formal) specifications that say which APIs you can use and its implemented by all runtimes. It is evolution of Portable Class Libraries (PCL). Specific runtimes implement specific version of .NET Standard (implementing specific set of APIs). E.g., .NET Framework 4.6.1 implements .NET Standard 2.0 (link).
The differences between .NET Standard and Portable Class Libraries (which is library that can be used on different platforms).
- .NET Standard represent set of API defined by Microsoft, while PCL is using API dependent on platform which is chosen.
- .NET Standard is platform agnostic, while PCL can target limited set of platforms.
Each version of .NET Standard has set of APIs (e.g. System.Drawing) and it include all APIs of previous version, so its backward compatible. Specific .NET runtime versions implement specific .NET Standard versions. Lower versions of .NET Standard cover more platforms, which means that you should always target the lowest version possible.
.NET Framework tooling
The purpose of the tooling is to make applications. For the .NET Framework tooling, use MSBuild, who is invoked when code is build in Visual Studio or it can be called from a command line. MSBuild knows how to build or who should compile them. If the code is C#/VB.NET he will call .NET Compiler Platform (Roslyn). The result of compilation is binary file (.EXE or .DLL) with intermediate language (IL). It can be interpreted by CLR. CLR contains JIT-compiler, which compiles to native code, which OS understands. CLR has tools like Garbage Collector to clean memory when not needed.
.NET Core tooling
MSBuild is also used in .NET Core tooling, as well as .NET Compiler Platform (Roslyn). It procudes binaries (.EXE, .DLL) with intermediate language (IL), which is used by the Core Common Language Runtime (CoreCLR). CoreCLR is different from .NET Framwork CLR, as it can run on multiple frameworks. It has JIT-Compiler that can compile IL into native code for Windows, MacOS and Linux.
There is another path to compile apps, when UWP is compiled, its compiled with AOT-Compiled (.NET Native), which produced Native code from IL and produced code as deployable package instead of compiling at runtime, which has performance benefit.
CoreCLR and Native Code is loaded by app host process (dotnet.exe).
.NET Core includes new Command Line Interface, called dotnet cli. It allows you to create new projects
dotnet new, build applications
dotnet build, run applications
dotnet run or deploy them
dotnet publish. You can try with
dotnet --info and check which SDKs and runtimes you have installed and on which disk location are they installed.
Mono for Xamarin tooling
MSBuild is used again to run build process but only for files in C#. If there are C# code for Android, its compiled via Xamarin Compiler and compiled for Android platform (IL). Then Mono Runtime, which as JIT-Compiler, takes IL and produces Native code specific for that Android device on demand at runtime. It has also runtime services such as Garbage Collector.
If we have C# code for IOS, its compiled via Xamarin Compiler, who pre-compile and produce package native for IOS (uses ARM Assembly language).
Visual Studio IDE
Visual Studio is a Microsoft IDE used for building, debugging, and publishing applications across all platforms, including Android and iOS. Visual Studio is integrated with .NET and provides the features of language-specific environment.
Visual Studio can be run on Windows and Mac. There is a free community version to be used. Visual Studio for Mac is totally different environment than one for Windows, as it is based on MonoDevelop, IDE for Linux, macOS and Windows, built by Xamarin company (earlier called Xamarin Studio).
Additionaly, it is possible to use Visual Studio Code to develop applications on .NET Core platform.
Outside Microsoft world JetBrains Rider is making an impact. By using it, one can develop .NET, ASP.NET, .NET Core, Xamarin or Unity applications on Windows, Mac, Linux.
There are different kinds of libraries that can be used in the .NET ecosystem, most of which can be found as NuGet packages. NuGet is a package manager build for .NET that contains more than 90,000 packages.
Different kinds of .NET applications can be written in C#, F# or Visual Basic.
C# is a simple, modern, object-oriented programming language, whose roots are in the C family of languages. The current version is 8.0 and is supported on .NET Core 3.x and .NET Standard 2.1. More on C# here.
F# is a cross-platform, open-source, functional programming language for .NET. More about F# here.
Visual Basic is traditional programming language from Microsoft kitchen with simple syntax for building type-safe, object-oriented applications. More on Visual Basic here.
The question is when to use each of the runtimes. This is a suggestion:
- .NET Framework should be used to:
- build Forms applications.
- that cannot run cross-platform (Windows).
- .NET Core should be used if:
- build high performance applications with small footprint.
- that run cross-platform.
- Mono for Xamarin should be used:
- build mobile applications that utilize native features and cross-platform.
If you use .NET Core you can use framework-dependent applications or self-contained applications. Use Framework-dependent if no target os is needed, you need small deployment (installed on machine). But for self-contained app there is control over version and .NET Core doesn’t need to be installed, but the deployment is larger and need to select target OS.
If we choose between ASP.NET or ASP.NET Core, ASP.NET is much older technology that runs only on Windows, but it has large set of capatibilites and features. ASP.NET Core can be run cross-platform and its designed for high-performance and can run self-contained. It has less capatibilites and 3rd party libraries than ASP.NET. No ASP.NET Forms.
Regarding the usage of sharing code, we need to check first do we need it. If yes, we should use .NET Standard library. If no, than we share code between applications in the same runtime, then we can use library with that specific runtime. This enabled runtime specific features not available in .NET Standard.
Look to the future
At the Microsoft Build 2019. conference, it is announced that .NET Core and .NET Framework will be unified in .NET 5. There will be only one .NET SDK to target different platforms, such as: Windows, Linux, macOS, iOS, Android, etc. This framework will consists of a new .NET APIs, runtime capatibilities and language features. One of the main topics for .NET 5 will be performance improvements over previous versions of .NET, as well as improvements to RyuJIT code quality, garbage collection, and JSON serialization. Release plan for .NET 5 is that it will ship in November 2020.
In addition, this year Microsoft announced that there will be a new first-class UI framework for creating cross-platform applications, called .NET MAUI. It will be an evolution of Xamarin.Forms and will simplify developer workflow and a project structure into a single project to target multiple platforms. General availability of the .NE MAUI will be with .NET 6 in November of 2021.
In 2018. Microsoft also introduced the ML.NET framework for C# and F# languages. So, looking at the latest trends, including Azure as one of the main Cloud platforms, future for the Microsoft-developer world is looking great. With open source and cross-platform as key priorities seems like a right direction in the years to follow.
.NET Guide – the general documentation by Microsoft for newbies.
.NET Core Guide – for those considering transitioning to the Core version.
.NET Framework – the original .NET documentation.
Xamarin – documentation for mobile development.
.NET Foundation – .NET open-source community.
NuGet – the place to find all .NET packages.
.NET Core and Framework – download it here.
.NET Developer Community – developer community and support with links to social media, forums, blogs, live workshops, and organizations like .NET foundation.
Thanks for reading !