NET Core: lighter, cross-platform and open-source

Home/.Net, Technical, Written by our colleagues/NET Core: lighter, cross-platform and open-source

We were used with Microsoft as being against open-source and using ‘vendor lock-in’ practices. In the past, in order to do development you needed Windows and Visual Studio which were not cheap at all. For hosting, IIS was necessary, which, of course, required Windows.

In the last years it seems that Microsoft executives have been trying to redeem themselves by pushing for open-source, cross-platform and free development environments. Based on GitHub Latest Statistics, Microsoft is the organization with the most open source contributors, outperforming organizations like Facebook or Google.

.NET Core is not just a continuation of ASP.NET 4.6, it is a whole new framework. It is much smaller, a lot more modular, it is open source and cross platform. Compared with the previous versions, it has the advantage of including only the relevant libraries instead of the whole framework.

Key characteristics:

  • Open Source – It is available here
  • Cross-Platform – Runs on Windows, macOS and Linux
  • Command-line Tools – Supports basic operations without needing an IDE
  • Thin, fast, modular – the entire platform delivered via NuGet

 

Installation

 

Maybe you are coming from an environment that allows you to start development right away, by installing a small package ecosystem and use commands for basic operations; Node.js, for example.

You can have a similar experience with .NET Core by only installing .NET Core SDK. You will be able to manage your project using the command line.

To keep the setup light, you can use Visual Studio Code which is an open source, cross-platform IDE. It comes with IntelliSense, Debugging features, Built-In Git, and many great add-ons. It also works great for JavaScript/Typescript development. You can see a comparison between Atom, Visual Studio Code, Sublime and Vim here.

 

If you are already used to Visual Studio, you can try the new Visual Studio 2017, which will come with all the good stuff, including .NET Core. The Community version is for free!

If you are worried that the installation will take much, you must know that the installer was redesigned, so that you can be more picky with the components you install. The minimum Visual Studio footprint was reduced and the installation is done more quickly.

The good news don’t end here: Visual Studio 2017 performance was significantly improved (launch time reduced with 50%). You can check the release notes here.

 

CREATE PROJECT

 

Let’s try the new command line tool:

dotnet new web

dotnet restore

dotnet run

Simple as that. This command line flow reminds me of node package manager, which allows you to quickly setup your project. With .NET command line, you can use the same approach to create the project, manage dependencies, run and build the project. The packages are managed through NuGet (similar with npm).  It feels like Microsoft tried to replicate some of the Node.js behavior. For the early versions of .NET Core, the dependencies were maintained using project.json (just like there is in Node.js), but it was replaced by the MSBuild/csproj format, which is XML based.

You can even use the command line with Yeoman, scaffolding tool for modern web apps, but you will need to install it through npm.

 

The project was created, let’s see how it looks:

It is pretty light, it has the .NETCore.App as a default dependency together with AspNetCore. The project also comes with a logging implementation, that is why it has another dependency for Application Insights.

All the dependencies are now retrieved using NuGet and the packages are stored in a common location for all the projects, so the packages will be cached and the project size will be smaller.

Program class contains the entry point method of the application. This is where the host is setup through the WebHostBuilder. The configuration for request pipeline that handles all the requests that are made to the application is done in Startup class.

 

ASP.NET Core and ASP.NET 4.6

 

.NET Core 1.0 framework was redesigned in order to produce a leaner and modular framework with better support for cloud base connected applications.

It comes with many great improvements like: integration with client side frameworks, cloud ready configuration system, lighter HTTP request pipeline, built-in dependency injection, and many more.

The ASP.NET Core is no longer using System.Web assembly, it is based on a set of granular NuGet Packages. The applications have a smaller footprint, improved performance and reduced servicing.

Let’s compare the size of the newly created ASP.NET Core project, with an existent ASP.NET 4.6 project:

The differences are quite impressive. Some improvement is because of the new package management, which are not stored in the project anymore, but in a centralized location. However, even after removing the packages from the old project, the size was still 14mb.

Another test was done to compare the memory usage of the IIS worker process, the Windows process which runs Web Applications.

The memory usage for the old application is about 3 times higher than the ASP.NET Core application.

ASP.NET Core MVC

 

If you want to spice things up a little bit, you can create an ASP.NET MVC Core project. You can do that using the command ‘dotnet new mvc’, or Visual Studio interface.

This will not only create a MVC project, but it will also use Bower for managing client-side libraries and it will come with a Bootstrap theme. Bundling and minification are also setup. You can easily add different client side libraries like: Gulp, Grunt or other.

 

Performance

 

ASP.NET Core performance increased significantly based on the benchmarks done by Techempower. On Round 13, ASP.NET was a pleasant surprise because it had the most dramatic performance improvement. For the Plain text tests, the improvement was amazing, compared with Mono, going from 2 120 requests to 18 223 600, making it 859 faster! For other tests the performance was not that drastic, but compared to previous versions, it is still pretty impressive. Microsoft has made a long plan commitment for improving performance, so more pleasant surprises are expected!

An alternative test, can be found on GitHub Asp Benchmarks.

 

Deployment

ASP.NET Core is not dependent on IIS anymore. It can be used with Kestrel, a cross-platform web server. If the application is exposed to the Internet, IIS, Nginx or Apache can be used as a reverse proxy server, which receives HTTP requests from the Internet and forwards them to Kestrel.

ASP.NET also has great support for Azure. The configuration for deploying a simple application can be done within minutes. The deploy can be done manually, by triggering a publish profile, or by using continuous integration, through Azure, for example.

You can find more details about how to publish the application to a Docker Image, or to a Linux Environment using nginx or using Apache Web Server.

 

Conclusions

ASP.NET 4.6 is a mature platform, so if you are looking for something that is already tested and has been running large websites for some time, you should probably stick with it.

However, if you want to be on the leading edge of technology, setup faster, enjoy the performance and develop and host the application on any platform, .NET Core should be your choice. This could help you decide.

Major improvements were also made in the documentation area. The sections are much clearer, and the articles are way more descriptive and easy to understand.

 

 Andrei Spatar
2017-03-30T13:31:41+00:00 March 23rd, 2017|Categories: .Net, Technical, Written by our colleagues|Tags: , , , , , , |

Leave A Comment