Introduction
Nowadays, everyone is talking about open source, cross platform development. Microsoft has always been known for its Windows based products, but now we are in the new age of development. For this, a new revolutionary product came into the market, which is Microsoft .NET Core.
.NET Core is a free open source and cross platform framework, created for building modern Cloud based Applications and every .NET developer feels proud of it. Now, there are no boundaries for the platform. Now, every .NET developer can say, yes I am platform independent, I am using an open source.
In the revolution of software development, Microsoft launched its first .NET framework in the year 2000 with its first .NET framework 1.0. This framework plays a major role in the field of software development. People love Microsoft technology products, because these products are easy to use and easy to learn.
When first time .NET framework came in to the market, it came with ASP.NET, C# and VB.NET, Web Services, multithreading, assembly and many things under this bucket. As time went by, .NET framework came with its many versions like 1.0,1.1, 2.0, 3.5,4.0,4.5, 4.6 etc. but all these frameworks support a particular platform and the platform was Windows. If I am talking about my journey, I got the chance to work in all the versions of .NET framework.
In the year 2016, Microsoft has come up with a new revolution, Microsoft .NET Core 1.0. People always love ASP.NET, because it's working over WorldWideWeb. Today in this article, we will learn about ASP.NET Core as an introduction.
ASP.NET Core is a new open source, cross platform framework to create modern Web based Cloud based systems, which means, now you are not only working for Windows, you can run in Linux, Mac; i.e., wherever you want.
ASP.NET Core features
- Cross platform, open source now runs your app over Linux, Windows, Mac; i.e., wherever you want.
- Fast Development- fast work over the Browsers.
- Work in your editors - now you can work not only in Visual Studio. You can also choose Visual Studio code and if you want to work on your command on the command prompt, then you can.
Now, the question arises, where you can download .NET Core, so here is the Website as you just need to log on to http://dot.net
Here, you can download Visual Studio 2015, .NET Core and Xamarin very easily.
Now, I am going to tell you what comes in .NET framework and what comes in .NET Core.
.NET framework includes
- ASP.NET 4.6 (System.web)
- Web Forms
- MVC
- Web API
.NET framework is known for Windows platform.
.Net Core comes with
- ASP.NET Core MVC
- ASP.NET Core 1.0 (Microsoft.ASPNETCore)
.NET Core is known for cross platform developments. Now, it's up to you, what’s your requirement, if you want to create apps, which can run over different platforms then choose .NET Core. If you are happy with Windows, you have .NET framework.
If you had already downloaded .NET Core from .NET Website (if not please download, it's free), so let’s do some coding on .NET Core.
First of all, if you want to know about your dotnet core info, just open the command prompt and type dotnet for example - C:\>dotnet and press enter.
You can see currently we have version 1.0.1.
If you had already worked on .NET framework, you always create your apps on Visual Studio. Today, I am going to tell you that you can create new .NET Core projects on the command prompt, then type yes in the command prompt.
Lets see how you can.
- C:\>Md testCore - this will create a new directory.
- C:\>cd testcore - this will enter you into the directory.
- now type c:\>dotnet new - this will create a new project.
- C:\testCore> dotnet new
Created new c# project in c:\testCore>
Now, open this Project over Visual Studio Code or Visual Studio. It's a simple C# app, which looks like this in Solution Explorer.
Let’s understand one by one its file structure.
- Program.cs
This is a normal HelloWorld console app. Here, you can change as per your requirement.
- using System;
- namespace ConsoleApplication {
- public class Program {
- public static void Main(string[] args) {
- Console.WriteLine("Hello World!");
- }
- }
- }
- project.json
This is JSON, which is going to tell you if your app is dependent on these dependencies. Hence, here you will add your future dependencies for an app.
- {
- "version": "1.0.0-*",
- "buildOptions": {
- "debugType": "portable",
- "emitEntryPoint": true
- },
- "dependencies": {},
- "frameworks": {
- "netcoreapp1.0": {
- "dependencies": {
- "Microsoft.NETCore.App": {
- "type": "platform",
- "version": "1.0.0"
- }
- },
- "imports": "dnxcore50"
- }
- }
- }
- project.lock.json
This is the full graph of your package.
Now, if you want to run your code press F5 or in the command prompt, write .NET and run it. If you are under folder in your command prompt, your app will run.
This is your first Hello app, you can test this app over Windows, Mac, Linux, as it up to you, because you have the power of cross platform.
Now, we will create our first ASP.NET Core app. For this, we will add some dependencies in project JSON file.
Add the code, mentioned below in to the dependencies section in project.json
- "dependencies": {
- "Microsoft.AspNetCore.Server.Kestrel": "1.0.1"
- },
What is Kestrel
Kestrel is a Webserver to run ASP.NET Core Applications. This is the reason due to which we will add the dependency, mentioned below.
Now create a host for this server, into program.cs
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http;
- using System;
- namespace ConsoleApplication {
- public class Program {
- public static void Main(string[] args) {
- var host = new WebHostBuilder().UseKestrel()
- .Configure(app => {
- app.Run(context => context.Response.WriteAsync("Hello in Asp.net Core"));
- }).Build();
- host.Run();
- }
- }
- }
- if ('this_is' == /an_example/) {
- of_beautifier();
- } else {
- var a = b ? (c % d) : e[f];
- }
As you can see in the code mentioned above, we have a host object with WebHostBuilder class and we configure app logic, build and run our host. Now, Press F5 and run the Project. Once you run the project, the screen looks, as shown below.
As you can see, your Application is hosted and you have a URL, which is localhost:5000. Now, open your Web Browser and type the URL and run it.
You can see our first ASP.NET Core app is running over the Web Browser. This was a simple introduction to ASP.NET Core. If you have any queries regarding this article, please write your comment in the comment box. Happy programming.