9

A Brief Walk-Through of the .NET Ecosystem

 3 years ago
source link: https://dzone.com/articles/a-brief-walk-through-net-ecosystem
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

A Brief Walk-Through of the .NET Ecosystem

This article provides insight into the many different tech stacks in the .NET ecosystem and how to navigate choosing the option for you.

Dec. 29, 20 · Web Dev Zone · Analysis

Join the DZone community and get the full member experience.

Join For Free

If you are working as a developer and want to switch to the .NET world, you will need to know what the possibilities for you are inside. The framework .NET is the most popular technology from .NET Ecosystem you can use 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 that we can build?

There is some confusion when trying to use a specific tech stack in the .NET ecosystem, as there are so many options, such as choosing which runtime to use. In this article, 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. Let's start with a brief history of .NET.

The History Behind .NET

During the 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, the .NET framework was known as the Next Generation Windows Services (NGWS). First, beta versions of the .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
  • .NET 5 (November 2020.): single .NET runtime and framework that can be used everywhere and that has uniform runtime behaviors and developer experiences.

The image below shows the timeline of the .NET main events.

.NET timeline

.NET Ecosystem: An Overview

Currently, in 2020, .NET Ecosystem consists of different components in the development platform. It encompasses different runtimes including the following:

  • .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.
  • .NET 5 (ASP.NET Core, WPF, Windows Forms, Blazor) - A unifying platform for desktop, Web, cloud, mobile, gaming, IoT, and AI applications.
  • Mono for Xamarin (IOS, OS X, Android) - Cross-platform.

All of the above runtimes implement the .NET Standard Library, which is a specification of .NET APIs that have implementations for each runtime. So, the code created for one runtime can be executed with another runtime.

All the runtimes use 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.

Runtime tools and infrastructure.

.NET Runtimes

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

.NET Framework is a software development framework for building and running applications on Windows. It is party open-sourced here. The .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 that 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 the application runs, CLR takes an assembly and uses a just-in-time compiler (JIT) to transpile machine code into code that can run on specific computer architecture.

Machine code.

.NET framework library contains classes, interfaces and values types that provide capabilities, 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).

The .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

.NET Core is one of runtimes in .NET Ecosystem. It was released in 2016, and it's open-sourced. It does not represent a new version of the .NET Framework and will not replace it. It's a completely independent version, which is build to allow the cross-platform capability 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 a .NET Core Class Library, which includes classes that provide different capabilities, and it's a smaller subset of the .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 the code below.

Shell
dotnet publish -r linux-x64 --self-contained
.NET Core logo.

.NET 5

.NET 5 is the latest runtime in .NET Ecosystem. It was recently released in November 2020 with a goal of unifying development for desktop, Web, cloud, mobile, gaming, IoT, and AI applications. The earlier setup goal was to produce a single .NET runtime and framework, cross-platform, integrating the best features of .NET Core, .NET Framework, Xamarin, and Mono. However, due to the global health pandemic, the unification was postponed to .NET 6 (expected to be released in November 2021). .NET 5 consists of App Host (dotnet.exe) that run CLR and Library. It has Common language runtime (CoreCLR) and a .NET 5 Class Library.

.NET 5.0 has a nearly identical platform support as .NET Core 3.1, for Windows, macOS, and Linux.

.NET 5 is installed in C:\Program Files\dotnet\shared\ Microsoft.NETCore.App[versions], which live side by side.

.NET 5 is a shared code base for .NET Core, Mono, Xamarin, and future .NET implementations. Also, target framework names (TFMs), which are used to express which version of .NET targeting, are updated, so we have now net5.0. This is for code that runs everywhere. It combines and replaces the net core app and net standard names and net5.0-windows that represent OS-specific flavors of .NET 5 that include net5.0 plus OS-specific bindings.

.NET 5 improve significantly single-file applications. Single-file applications are published and deployed as a single file, which includes the app and all of its dependencies. They can also be self-contained, which means they carry their own .NET runtime. .NET 5 brings smaller single-file applications with more efficient memory usage and can be used in microservices containerized applications.

In addition, one of the important new features is support for ARM64, that will allow .NET 5 applications to run natively on Windows and ARM hardware, such as new Apple M1 ARM-based processors.

.NET 5 platform.

Mono for Xamarin

Mono is a clone of .NET framework runtime. Mono is created in 2001., but part for Xamarin was released in 2011, and it's open-source, which can be found here and here. 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 the 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.

Xamarin logo.

Other frameworks: .NET Compact Framework and .NET Micro Framework

These are specific frameworks with a specific purpose. Both runtimes were attempted 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

Silverlight was a popular cross-platform, .NET technology that enabled building rich media experiences for browsers. It was released on 2007 and had multiple capabilities such as playing videos, download medias, creating rich UI and animations, etc. In 2015. Microsoft decided to stop supporting Silverlight in October 2021.

Community Projects

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 slightly different approach to build such a framework.

.NET Standard

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 and .NET 5 implements .NET Standard 2.1 (link).

.NET Standard library.

The difference between .NET Standard and Portable Class Libraries is a 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.

In .NET 5 .NET Core and .NET Standard are merged, which means that we now have a shared code base for all .NET workloads, whether it’s desktop apps, cloud services, or mobile apps. New TFM net5.0 will represent the API set that available on all platforms. In addition, OS-specific TFMs are added (such as net5.0-windows) that targets all of the .net5.0 + APIs specific to Windows.

Shared code bases for .NET workloads.

In general, we can use: * netstandard2.0 to share code between .NET Framework and all other platforms. * netstandard2.1 to share code between Mono, Xamarin, and .NET Core 3.x. * net5.0 for code sharing moving forward.

Tools

.NET Framework Tooling

The purpose of the tooling is to make applications. For the .NET Framework tooling, use MSBuild, which is invoked when code is built 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 and .NET 5 Tooling

MSBuild is also used in .NET Core tooling, as well as .NET Compiler Platform (Roslyn). It produces binaries (.EXE, .DLL) with intermediate language (IL), which is used by the Core Common Language Runtime (CoreCLR). CoreCLR is different from .NET Framework 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 the 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).

As a side note on Xamarin, it also has different competitors, such as Uno Platform and Avalonia UI. There is also a new kid in the block from Microsoft, called Blazor. All of these tools mainly uses WebAssembly (WASM) in combination with C# and XAML or JavaScript to allow developers to deploy apps in the browser, but also on different devices.

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).

Visual Studio Code.

Additionally, it is possible to use Visual Studio Code to develop applications on .NET Core platform.

Outside Microsoft's 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.

Libraries

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.

Languages

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 9.0 and is supported on .NET 5 and .NET Standard 2.1. More on C# in general here and on C# 9.0 features here.

F# is a cross-platform, open-source, functional programming language for .NET. More about F# here.

Visual Basic is a traditional programming language from Microsoft kitchen with simple syntax for building type-safe, object-oriented applications. More on Visual Basic here.

CSharp.png

Usage

The question is when to use each of the runtimes. This is a suggestion:

  • .NET Framework should be used to build Forms applications or applications that cannot run cross-platform (Windows).
  • .NET Core should be used to build high performance applications with a small footprint or applications that run cross-platform.
  • .NET 5 should be used for all new development or applications that run cross-platform.
  • Mono for Xamarin should be used to build mobile applications that utilize native features and cross-platform.

If you use .NET Core or .NET 5 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 and .NET 5 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 a much older technology that runs only on Windows, but it has a large set of capabilities and features. ASP.NET Core can be run cross-platform and it's designed for high-performance and can run self-contained. It has less capabilities 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 are not available in .NET Standard.

Looking to the Future

As .NET 5 didn’t bring all planned features, due to some technical problems but as well as delays caused by COVID-19 pandemic, some of the original plans for .NET 5 shifted to .NET 6 coming in November 2021, which will be a Long-Term Support (LTS) release. We can see .NET 5 as a first step in the .NET journey. .NET 5 is a key technology for the separation of the Windows APIs from the OS, the Project Reunion merger of WinRT and Win32 APIs, and the move to both WinUI 3 and MAUI as UI layers. The Windows team continues to work on Project Reunion as the next step forward for UWP and related technologies.

.NET schedule.

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 addition, 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, the 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.

Useful Links


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK