Hey, folks, I have been playing around with.NET Core for 1 month and there is still a lot to cover. Though by considering.NET CORE as a sea, which is then further divided into lagoon, lakes, ponds and rivers in the form of ASP.NET MVC, Entity Framework Core, ASP.NET CORE etc., I have no hesitation saying that I just had a few drops of rain over my mind and I felt really good to feel the monsoon coming for .NET developers, where we can see lots of new features coming to the .NET stack cross-platform, with performance benchmarks and open source.NET technologies, which makes Microsoft open to the world. I am a just normal developer, who had no knowledge of open source before, as I never heard from the colleagues or I should say, I was not involved with the community. With .NET being open source now, we have .NET core, which is built from scratch by running cross platforms, and cheap deployment on a a Linux machine, which was not possible before (Note*- Windows Servers are costly compared to Linux Servers). Thus, let's get started by digging into Core. If you want to get started with .NET Core with the steps for downloading SDK my honest suggestion is to go to my previous blog, as mentioned below.

Introduction

I believe that if you have followed each and every step as mentioned in the blog to start using .NET Core and you are happy to run your basic set of "HelloWorld" programs, which run just fine on Windows, Linux or Mac. Going forward, let's talk about how .NET and .NET Core are different from each other. .NET Core is NuGet based, which means all the dependencies are in the form of NuGet packages, which allow a local app deployment while in.NET Framework, and we have to be dependent upon .NET framework. Every time the new feature is added in the component of .NET Framework, the Microsoft team has to ship the new framework for the same, which results in waiting until a given .NET Framework version is widely adopted. With the help of a NuGet based approach, an Application deploys the new version without waiting for a .NET Framework to be widely accepted resulting in the easy upgrade to the components.

Command line Tooling

Command line Tooling gives us command line features to run and create the ASP.NET or.NET CORE Application with the help of any Text editor. We don't need our own Visual Studio to create and publish Web Applications. All the compiler, runtime and command line toolings are installed in a single go with a single install of SDK. Some .NET Core related commands are given below.

Previously in.NET Framework, we used to have our executable file EXE. In .NET Core, we are not running any EXE in order to run our program; we simply run .NET run in a folder that contains the project.json file because project.json files contain all the instruction and dependencies details for the application. The code of our C# application is compiled into .dll. This DLL is then loaded by .NET runtime loader, which hosts the DLL, when we run .NET run command. There is no mainline exe for the same. We can create a wrapper EXE for frameworks by targeting the runtime as specified below: Set the runtime in Project.json file and run .NET restore.

  1. "runtimes": {
  2. "win10-x64": {},
  3. "win7-x64": {},
  4. },

When we build the Application, run the command, given below.

dotnet build -r win10-x64

5

This will generate the wrapper exe file which will in turn run via .NET runtime. We need to ensure that we remove the platform attribute from the project.json file, as shown below.

  1. "dependencies": {
  2. "Microsoft.NETCore.App": {
  3. "version": "1.1.0"
  4. }
  5. },

This is done because I am not going to use .NET Core platform, which has been installed and I will use local version. Here is my Project.json with runtimes, to which I am referring

  1. {
  2. "version": "1.0.0-*",
  3. "buildOptions": {
  4. "debugType": "portable",
  5. "emitEntryPoint": true
  6. },
  7. "runtimes": {
  8. "win7-x64": {},
  9. "win10-x64": {},
  10. "osx.10.10-x64": {},
  11. "ubuntu.14.04-x64": {}
  12. },
  13. "dependencies": {},
  14. "frameworks": {
  15. "netcoreapp1.1": {
  16. "dependencies": {
  17. "Microsoft.NETCore.App": {
  18. "version": "1.1.0"
  19. }
  20. },
  21. "imports": "dnxcore50"
  22. }
  23. }
  24. }

Once I run .NET build command with the respective runtime, it will create a folder for the same with the respective files. Here, we are talking about the context to generate the EXE file, so I will target win7-x64.

6

Once our progam gets compiled, let's check our executables.


Fig.4. Wrapper exe generated targetting the specific framework.

Now, if I try to run EXE file, it will work as it used to work with .NET Framework. This EXE isn't an app but it's just a wrapper around dotnet.exe to run it on a click rather running .NET run.


Fig.5 Example Hello World.

Where is my ASP.NET?

I have been talking about console Application but the majority of our enterprise applications are Web based. ASP.NET Core projects are console Applications, which will run the Server execution environment and then process our http requests. We will look into the granular level, so that we will be aware of how the things are implmeneted in ASP.NET Core. In order to evolve our console Application to Web Application, I will be using Visual Studio code to show this demo, so that we will be aware of how Visual Studio code can help us building .NET Core Application cross platform (*Note: We can use other IDE as well). With incremental updates of VS Code, it's one of the best text editor tools to build the Web based Application easily. Thus, we will create a new project and open the project in Visual Studio code, using code, as shown below:


Fig.6. Example Opening .NET core project in VS code.

Once we are are done opening the project in VS Code, the screen given below will appear.


Fig.7. Setting up Visual studio code task and launch.json

Click Yes and Restore

Restore will run the .NET restore command for you and download all the necessary dependencies in order to run the program. Once we allow VS code, do all the manual things, which we did earlier, now, all the things will be taken care of by VS code and the respective Extensions.Vs code is smart enough to know the kind of project. It determines this is .NET Core project, creates the task and launches a .json file for the project to run and builds the same easily with the task.


Fig.8.Example VS code creating the tasks for the projec to run.

Now, let's run our program and see the power of kestrel. I know this might be confusing regarding how all the things are working. I will explain it all, once we are done launching our first ASP.NET to the Browser. We need to first build our program and then run it with F5. I hope, our first launch of ASP.NET is successful just like ISRO launches the satellites.

Ready steady Go

12

We have successfully launched a small Web Application with a simple hello world application. I hope, this article will be helpful to you to dig into the pipelines of .NET CORE. Keep reading and keep sharing.