A while back we predicted that .NET Core would be the next big thing, offering developers many options in application development. Indeed, there is huge demand for developers skilled in this technology. But how does it differ from the .NET Framework, and what do you need to know to use them both effectively?
Today, we’ll contrast .NET Core vs. .NET Framework to help you choose which one to use for your next project. In this post, we’ll explain their key differences and how to make the best use of each. Let’s begin with a background on .NET.
Historically, the .NET Framework has only worked on Windows devices. The Xamarin and Mono projects worked to bring .NET to mobile devices, macOS and Linux. Now, .NET Core provides a standard base library that’s usable across Windows, Linux, macOS and mobile devices (via Xamarin).
There are four major components of .NET architecture:
Microsoft maintains both runtimes for building applications with .NET while sharing many of the same APIs. This shared API is called the .NET Standard.
Image via Wikipedia
Developers use the .NET Framework to create Windows desktop and server-based applications. This includes ASP.NET web applications. On the other hand, .NET Core is used to create server applications that run on Windows, Linux and Mac. It does not currently support creating desktop applications with a user interface. Developers can write applications and libraries in VB.NET, C# and F# in both runtimes.
C# is an object-oriented language similar to other C-style languages. The learning curve should not be a problem for developers already working with C and similar languages.
F# is a cross-platform language that also uses object-oriented programming.
Visual Basic is available in .NET Framework with limited .NET Core support with .NET Core 2.0.
A cross-platform and open-source framework, .NET Core is best when developing applications on any platform. .NET Core is used for cloud applications or refactoring large enterprise applications into microservices.
Screenshot via Microsoft.com
You should use .NET Core when:
.NET Core does not have some of the .NET features nor support for all libraries and extensions. As such, you may encounter a few situations in which .NET Core may not be the best option (though continued development will likely eliminate this drawback). Consider the following scenarios:
.NET Framework is distributed with Windows. Generally, it is used to build Windows desktop and large-scale enterprise applications using .NET workflow and data connection tools.
The .NET Framework provides services that include:
.NET Framework can be used with Docker and Windows Containers and is most feasible when:
There are also a few situations in which you shouldn’t run the .NET Framework. These include when:
If and when you decide to migrate your .NET Framework to .NET Core, follow these steps (after a proper assessment, of course):
More than just knowing what the third-party dependencies are, you need to understand how the application functions with the third-party dependencies that run on .NET Core. You also need to be aware of what needs to be done if they do not run.
NuGet packages are easy to check plus the package has a set of folders for each platform. You can also look for a folder or entry on the Dependencies page with any of the following names:
netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 netstandard1.4 netstandard1.5 netstandard1.6 netcoreapp1.0 portable-net45-win8 portable-win8-wpa8 portable-net451-win81 portable-net45-win8-wpa8-wpa81
If the dependencies are not NuGet packages, the ApiPort tool can check the portability of the dependency.
Since .NET Core 2.0, a compatibility shim allows referencing .NET Framework packages that haven’t been switched to use .NET Standard. Be sure to thoroughly test these packages as they may still have issues if they use unsupported APIs.
The .NET Standard library is intended to be available on all .NET runtimes. So, targeting the .NET Standard library is the best way to build a cross-platform class library.
There are multiple versions to consider that are available to varying degrees across eight platforms. If a project targets a lower version, it cannot reference a project that targets a higher version. Pick the lowest possible .NET Standard version to use across all projects. Below is a chart with each .NET Standard version that shows the specific areas they run on:
Screenshot via Microsoft.com
All the projects to be ported need to be targeted to .NET Framework 4.6.2. This will ensure API alternatives for .NET Framework specific targets can be used for non-supported APIs.
This is done easily in Visual Studio with a “Target Framework” command and recompiling the projects.
Porting code to .NET Core is a significant change; testing is strongly encouraged. Use a suitable testing framework such as:
With tools like xUnit, it’s possible to use templates and edit them to write .NET Core tests. Here’s an example of an edited .csproj file:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp1.1</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="xunit" Version="2.3.0-beta2-build3683" /> <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta2-build3683" /> </ItemGroup> </Project>
The best way to port the code depends on how the framework is structured. But breaking the code base into steps and layers should work well. Here is how to do it:
Xamarin may sound like a new prescription medication. However, Xamarin is a platform for developing apps that run on iOS, Android or Windows Phone devices.
Xamarin is written in C# and available in all editions of Visual Studio.
Microsoft promises that Xamarin is the best way to create a user interface (UI) and optimize performance in apps on multiple platforms. This is important today when apps need to run on at least iOS and Android devices.
Xamarin shares code across platforms and uses a single technology stack to decrease time to market and engineering costs. But user interface-intensive apps may need more platform-specific coding. The amount of code sharing and savings then decreases.
In addition to .NET Framework, .NET Core and Xamarin, .NET Standards also supports the following platforms:
All these platforms will implement .NET Standards – a common set of APIs that replace portable class libraries (PCLs). This ensures code sharing across desktop applications, mobile apps, mobile games and cloud services.
It’s important to always have a good APM in place for your .NET application. Retrace is a great full lifecycle option that you can try for free.
You can also try Netreo’s free code profiler Prefix to write better code on your workstation. Prefix works with .NET, Java, PHP, Node.js, Ruby and Python.
Stackify's APM tools are used by thousands of .NET, Java, PHP, Node.js, Python, & Ruby developers all over the world.
Explore Retrace's product features to learn more.
Join the 40,000 developers that subscribe to our newsletter.
If you would like to be a guest contributor to the Stackify blog please reach out to stackify@stackify.com