.NET Core: An Introduction
Microsoft released the very first stable version of .NET Core to the public back in 2016, and development on it has been moving at a rapid pace since then. In just under 4 years we’ve seen the release of three major versions of the framework, with contributions coming from both Microsoft and the open-source community.
With the major version available, a lot of companies are looking to .NET Core to see whether the need to migrate their applications over to the latest incarnation, but what is it and why would you want to look into .NET Core?
What is .NET Core?
.NET Core is a cross-platform, open-source set of APIs which form a framework for rapidly developing applications. The list of APIs that .NET Core supplies are laid out in something called the .NET Standard (which we are planning a future blog post on) as does .NET Framework (which is what we used to mean by .NET), Mono and Xamarin also adhere to this standard.
The .NET Framework has been a Windows-only framework since it was first released in 2002, meaning that applications built with .NET Framework would only work on Windows. But since .NET Core is cross-platform, it means that applications written in .NET Core can run on Windows, macOS, or Linux distributions. This means that hosting options for applications open up and potentially can become cheaper, as you are no longer locked down to using Windows servers to host your applications.
.NET Core is modular by design, this means that when your source code is built if there is code in a supporting library which isn’t needed, it can be removed. Because of its modular nature, .NET Core applications tend to be a lot smaller than .NET Framework applications, this means that .NET Core applications can run in much more confined systems like Raspberry Pi or within small Docker images. Because of this, .NET Core is ideal for creating and running microservices which need to be spun up, replicated, and shut down with ease.
Whereas .NET Core is modular, .NET Framework is both monolithic and tied to Windows. As such, .NET Framework applications require the presence of the entire .NET Framework to run. Because .NET Framework is so large, booting an application written with it can take a lot longer than booting an application with built with Core - most web applications written with Framework can take upwards of 10 seconds to start, whereas most web applications written with Core can start in a matter of milliseconds.
What can you build with .NET Core?
Almost any kind of application can be built with .NET Core, as it supports both Object Oriented and Functional paradigms. It also has a very large library of open source packages, similar to the npm library - doubtless, if you can think of it there will be library which either implements it or is designed to help you implement it.
Every application written in .NET Core starts at the command line (or terminal), as such, they are all command-line based applications.
Hello World in .NET Core
The above image shows Hello World written in C# and .NET Core. On the left-hand side of the image is Visual Studio Code showing the code required to run Hello World, and on the right-hand side is a terminal window with the application running.
But .NET Core applications are so much more than just command-line based, with .NET Core you can build:
- Command-line applications (as we’ve seen)
- Forms-based GUI (graphical user interface) applications
- Full web applications
- Mobile applications using Xamarin
Some examples of applications built with .NET Core are:
- Bing, the web search engine by Microsoft is written entirely in .NET Core
- Stack Overflow - the team behind one of the biggest web applications in the world are in the process of migrating it to .NET Core
- Umbraco - one of the largest .NET CMSs is migrating to .NET Core this year
- Intentity Server - the leading identity service for .NET is written in .NET Core
Where Can .NET Core Applications Run?
Because .NET Core is cross-platform, with tooling which supports targeting many different platforms, almost any .NET Core platform can run on a large number of different environments. For instance .NET Core applications can run on:
- Many different Linux distributions (including Ubuntu, CentOS, Fedora, and many others)
- Raspberry Pi
- Wilderness Meadow
- Android and iOS (via Xamarin)
- Samsung TVs and Fridges (via Samsung’s Tizen operating system)
But what about the cloud? The majority of the cloud infrastructure suppliers have you covered, as it is possible to run .NET Core applications in:
- Azure from Microsoft
- AWS from Amazon
- GCP from Google
- Digital Ocean
- And many more
One thing to note is that whilst typically Azure, AWS, and GCP have one-click set up processes or can even build and deploy directly from your source control provider, other provides will require a much more manual process. For instance, both Linode and Digital Ocean require a system administrator to install the .NET Core runtime manually before deploying, and Netlify only supports one specific hosting method (favoured by Blazor - we have a blog post on what that is coming soon).
Why should I choose .NET Core over .NET Framework
When .NET Core was first announced, many developers thought that the .NET Framework would be abandoned. This is simply not the case. The simplified version is: .NET Framework has the same support cycle as the Windows operating system. As long as Windows is supported, the .NET Framework will be supported. It is not going anywhere anytime soon.
Beginning with version 4.5.2 and later, .NET Framework is defined as a component of the Windows operating system (OS). Components receive the same support as their parent products, therefore, .NET Framework 4.5.2 and later follows the lifecycle policy of the underlying Windows OS on which it is installed … There is no change to the lifecycle policy for .NET Framework 4.x and its updates which continue to be defined as a component of the OS and assume the same lifecycle policy as the Windows version on which it is installe
With that being said, Microsoft has announced that no new features will be added to .NET Framework going forward. However, security updates and bug fixes will continue to roll out to it:
.NET Framework 4.8 will be the last major version of the .NET Framework. If you have existing .NET Framework applications that you are maintaining, there is no need to move these applications to .NET Core. We will continue to both service and support .NET Framework, which includes bug–, reliability– and security fixes. It will continue to ship with Windows (much of Windows depends on .NET Framework) and we will continue to improve the tooling support for .NET in Visual Studio (Visual Studio is written on .NET Framework).
Whilst .NET Core is the future of .NET development, there are some APIs and features which are present in Framework but missing in .NET Core. For instance, Windows authentication is simpler to achieve in Framework - because of it’s cross-platform nature, Core cannot include support for Windows-specific authentication.
So the rule of thumb currently is: if you are creating a greenfield project which doesn’t rely on Windows-specific things, go with Core. If you are supporting a legacy Framework application, consider breaking parts off of it into microservices. And if you require Windows-specific APIs, stay with Framework.
How do I get started with .NET Core?
The great thing about .NET Core is that you don’t have to install anything to get a feel for it. Microsoft has created a wonderful resource called try.dot.net which allows you to run .NET Core applications inside your browser.
Hello World, running in an instance of Firefox
The above image shows the same Hello World application running in Firefox, via the try.dot.net website.
Once you are familiar with .NET Core in the browser, you might decide to download the SDK (software development kit) which can be found at dot.net/core. This contains everything you might need to build applications in .NET Core - everything aside from an IDE (integrated development environment). We would recommend any of the following IDEs for .NET Core development:
Some things to remember: Visual Studio and Rider are paid products, so there may be licensing to consider, whereas Visual Studio Code is free.
Once you have these tools installed, you will have everything that you need to build .NET Core applications. But you might need some training on creating applications with .NET Core, for this, we’d recommend dot.net/videos.
These videos are written and hosted by the developers of .NET Core themselves and are targeted at .NET Core beginners. The videos are hosted on both YouTube and Channel9 - this means that if you can’t access YouTube for some reason, they should still be available for direct download from Channel9.
The future of .NET
As mentioned above, the official guidance for creating new applications using a .NET technology states that you should consider using .NET Core where possible. One thing to know, however, is that Microsoft are looking to re-brand .NET Core in November of 2020. As of November 2020, .NET Core will be re-branded to .NET 5.
We’re skipping the version 4 because it would confuse users that are familiar with the .NET Framework, which has been using the 4.x series for a long time. Additionally, we wanted to clearly communicate that .NET 5 is the future for the .NET platform.
We are also taking the opportunity to simplify naming. We thought that if there is only one .NET going forward, we don’t need a clarifying term like “Core”. The shorter name is a simplification and also communicates that .NET 5 has uniform capabilities and behaviors. Feel free to continue to use the “.NET Core” name if you prefer it.
The reasons for this are varied, but the major reasons are relating to unifying the following platforms into a single runtime and framework:
Mono is a version of .NET Framework which was originally released in 2004 by a team of engineers lead by Miguel de Icaza and was conceived as a way of running .NET applications on Linux and macOS.
Xamarin is a framework which was originally built on top of Mono to allow for cross-platform mobile application development using C# and .NET. In order to build an app for both Android and iOS before Xamarin, you would need two separate code bases (one for the iOS version and one for the Android version). Xamarin simplified mobile app development by using a technique called cross-compilation: all app code was written in .NET, but at deployment time the code would be translated into Swift (for iOS) and Java (for Android).
Bringing both Mono and Xamarin, along with .NET Core, into a single framework enables the use of the Mono Linker, support for Xamarin Forms, and various optimisations. The Mono Linker allows for applications to be smaller and require less memory - required for technologies like Blazor, which we will be writing about soon. And Xamarin Forms could allow developers to create cross-platform .NET desktop applications with User Interfaces - something which isn’t easy to achieve at the moment, unless Avalonia or Uno Platform.
Along with the new name, comes a new release schedule:
Updates to .NET Core are released on a regular basis throughout the year - usually with a cadence of around three to six months between releases. From .NET 5 however, the release cadence will be relaxed and new major releases will happen once per year.
As you can see, .NET Core is a major contender for cross-platform application development. Applications written in .NET Core can be small, fast to boot, and quick to scale; but if you require Windows-specific APIs (such as Windows-based authentication), you might be better of sticking with .NET Framework.
One thing to remember, however, is that .NET Core will soon be renamed to .NET 5, and its version number will increase each year.
About the Author
Jamie Taylor is a .NET Contractor, podcaster, speaker, and creator of several open-source libraries and applications.