Why web developers need to move to .NET Core and using ASP.NET Core MVC to build Web and Web Services/API instead

This is my personal opinion and I have a good reason to recommend developers to move to .NET Core instead of .NET Framework. Some might disagree with my opinion, but hey, it’s good to share thoughts and to discuss it. I’m not going to tell what is .NET Framework as you can just Google it, but I can assure you that .NET Framework can only be run on a Windows Operating System machine.

Drawing The Line

There will always be a reason for developers or their team lead to saying that their system is still using old system which is obviously happen to enterprise developers. So, I will draw some lines on who should move to using .NET Core instead of .NET Framework. Here is what is in my mind:

  1. If you are a maintainer of a legacy Windows services backend, web apps or web services, than you need to keep using .NET Framework for now.
  2. If your apps will be deployed on an old Windows Server machines, than you might want to stick with .NET Framework for now.
  3. If you are a VB developers which only relied on VB.NET language, than you have to use .NET Framework.
  4. If you are sure that your system won’t be deployed to a cloud very soon, than you can stick with .NET Framework for now.
  5. If you are stuck without any option whatsoever to use .NET Framework, than you need to continue using .NET Framework.

Beginners, just learn .NET Core instead!

If you are a beginners learning ASP.NET or ASP.NET MVC, you probably don’t know what is .NET Framework and .NET Core is. No worries! I suggest and recommend that you look at the documentation and you can see the comparison and the differences easily. And just use .NET Core instead of .NET Framework. Here is what I can share some of the bits of both .NET Framework and .NET Core and you can click on each links to get the tools to start developing.

.NET Framework .NET Core
Technology First Release 2002 (Mature) First Release 2016 (Mature)
Latest Version 4.7.1 (Reference Source) 2.0.3 (Open Source Software)
SDK Version 2.1.3
SDK Windows Only (Version 7, 8, 10) Windows (Version 7, 8, 10),
Linux (redhat, Ubuntu >14.04, Fedora, Debian, CentOS 7, openSUSE 24, Oracle Linux 7, SLES 12),
Mac
ASP.NET Performance 57,843 Request/Seconds (Plain Text) 1,822,366 Request/Seconds (Plain Text)
Here is some real world news as reference: ASP.NET Core – 2300% More Requests Served Per Second.
Best IDE/Editor Visual Studio 2017 Community (latest, FREE) Visual Studio 2017 Community (latest, FREE),
Visual Studio Code for Windows, Linux and Mac (FREE),
Visual Studio for Mac Community (FREE)
Web Framework Web Form, ASP, MVC (Web and Web API) MVC Core (WebRazor PageWeb API)
Entity Framework (ORM) Entity Framework 6.2 (latest)
(Microsoft SQL Server, Oracle, MySQL (Official), PostgreSL, SQLite, IBM Data Server (DB2))
Entity Framework Core 2.0.1 (latest)
(InMemory (for Testing), Microsoft SQL Server, SQLite, PostgreSQL (Npgsql), IBM Data Server (DB2), MySQL (Official), MySQL
(Pomelo), Microsoft SQL Server Compact Edition, Devart (MySQL, Oracle, PostgreSQL, SQLite, DB2, and more),
Oracle (not yet available), MyCat, Firebird-Community)
Frontend Plain MVC, Angular (mostly using MVC) Plain MVC, Angular, React, and Redux

5 Minutes Start using .NET Core

If you already have a laptop while reading this, download and install JUST the .NET Core SDK based on your Operating System (Windows, Linux, Mac). You don’t have to install Visual Studio 2017 first to develop using .NET Core. Once you have installed the SDK, open Command Prompt or PowerShell (in Windows), Terminal (in Linux or Mac), type this:

dotnet new console -o myApp
cd myApp
dotnet run

Done! Congratulations, you just create your first Console App using .NET Core. Now you can deploy by publishing this app to any platform you want. Example for publishing to be run on Mac machine,

dotnet publish --runtime osx-x64

or for Android,

dotnet publish --runtime Android

Here is the full list of the runtime identifier catalog. So, what does this command actually do:

dotnet new console -o myApp

When we execute this dotnet command, it’s actually creating a Console application project on myApp folder. If you look at myApp folder, you should see this files:

myApp.csproj
Program.cs

The Program.cs file it self is just a simple Hello World snippet.

If you execute this command,

dotnet new --list

It will list the available template out of the box. Here is what you might see,

dotnet new –list

And the one that is on the red box is the console application template that we use. If you replace the console with mvc than it will create a web application project that uses ASP.NET Core MVC. Go ahead and try other projects template for start and see the differences.

Migration to ASP.NET Core means Migrate to Modern Web App

Can I just migrate to ASP.NET Core? Easy answer is No, you cannot do it directly! You cannot just open Visual Studio 2017 and open your old ASP.NET Web Forms or MVC 5 to ASP.NET Core MVC. Here is my strategy for migration of old codes,

  1. If your current web app is using Web Forms, you CANNOT directly convert or migrate to ASP.NET Core. Why, because Web Form and MVC has different architecture model. MVC uses separation of Model, View and Controller. Also has no web form Controls components like in Web Forms. ASP.NET Core MVC uses pure HTML5 elements. You can create a TagHelpers to create custom HTML attributes which will be converted in to normal HTML5.
  2. If your current web app is using ASP.NET MVC 5, you can copy-paste SOME of the codes to ASP.NET Core. This will need a bit of tweaking, especially on the Razor Page side. You have to create a new ASP.NET Core MVC project first.
  3. If your current web app is just a Web API backend, you can copy-paste SOME of the codes to ASP.NET Core Web API project. You may need to create a new Web API project first, than copy some of the codes. Tweaking is required here as ASP.NET Core Web API is using Web API 2.
  4. Use HTML5! What is HTML5? HTML5 is for modern web app standard only. Use HTML5 that is from W3C (World Wide Web Consortium) Standard. And not just standard from Microsoft Edge, Chrome, Firefox, etc. Because each browser has its own capabilities called PLATFORM standard and some of the browser platform feature DOES NOT become W3C Standard. If you use only Chrome feature standard, your web might end up stuck with Chrome only and cannot be open on other browser. Not all browser agree with other browser feature. To check whether the feature is standard, you can start using http://caniuse.com or for Microsoft Edge platform feature, you can check through the platform status site https://developer.microsoft.com/en-us/microsoft-edge/platform/status/. Anything that has been indicated as Supported means has been released and you can use it. You can also check which one are still under development, preview, deprecated, etc.
  5. Responsive, responsive, responsive! I sometimes heard developer said, “no we don’t need responsive, this is only for desktop browser, we just make it static layout“. Well, here is my suggestion, DON’T! Try to make it responsive as you can. If your site is for consumer/public, than you have to do it responsive as more users will use their mobile apps browser to view. Responsive also does not mean you must use the Twitter Bootstrap CSS. This Bootstrap is only one of the most use Responsive layout CSS.
  6. Try not to use CSS directly on the development project. Use SASS or LESS. You can do this easily using ASP.NET Core. And you can even add Gulp or Grunt to do the compiling to CSS. Also remember in Visual Studio 2017, you have the Task Runner Explorer to manage the Gulp or Grunt easily.

If your codes are properly develop by following S.O.L.I.D Principle, I believe, the migration should be easy and not so many tweaking. However, if your code is like spaghetti than my rule of thumb is Re-Code entire application and fork as many non-dependent codes from the old projects. It is better to do it now rather than not. The good thing is, you get to learn something new and including mistakes. The benefit is, your new web app will have better performance, modern and maintainable.

Say to your Boss: Move to .NET Core

I know what your boss will reply, yes, that horror statement, “is it compatible?

My suggestion, say: “YES, it is Compatible! It’s just .NET. But we need some tweaking and some need small coding changes

While I’m not forcing anyone to use .NET Core, but you can see the strategy and the lines that I have mentioned above. The spirit here is, if not now, then when? It is entering 2018 now and everything has changed. Technologies has changed (Modern Web Apps, Mobile, Augmented Reality, etc.), infrastructure has changed (Cloud, AI), development architecture has changed (Containers, Serverless), etc.

Not that Easy

Of course. But, does not mean cannot. It require a courage and knowledge. I hope that will give some insight facing 2018. Enjoy, Happy New Year 2018 and Happy Coding!

May the .NET Force Be With You!

Resources FREE eBooks:

Architecting Modern Web Applications with ASP.NET Core and Microsoft Azure
.NET API Browser
Web Applications with ASP.NET Core Architecture and Patterns guidance