Introduction to .NET Core - Basic Introduction with Visual Studio 2015 and 2017

Till now website/application developed using .net framework can be hosted only on windows platform. So, your application is bounded with windows OS. What if someone wants to deploy .net framework based application on Linux or Mac, earlier there was no solution but now it can be achieved using.NET Core. So let's start by introducing.NET Core.

What is .NET Core?

The asp.net core is a new open source framework introduced by Microsoft.

ASP.Net Core is a cross-platform open source framework for building modern applications including cloud-based development.

ASP.Net Core is designed to support client-side frameworks like KnockoutJS, Angular JS and Bootstrap.

ASP.Net core has various architectural changes which make it a great framework for a developer. You can say it's a new version of .net.

.Net is a development framework given by Microsoft. Application developed in .Net can be hosted in Windows environment only. The first version of .Net was released in the year 2002.

From .Net version 1.1 to .Net 4.6 there are numerous features which were added and yes those features have been used widely in industry. But there was a limitation with .Net framework.
Application developed in .Net framework can be hosted in Windows environment only. Means .Net framework given by Microsoft can run within Windows OS given by Microsoft.

So, people from Linux or Mac background cannot utilize those .Net based application.

To open this boundary Microsoft introduces its open source framework and named it as .Net Core.
.Net Core provides a new way to develop an application and gives you the flexibility to develop application in your favorite environment on your favorite tool.

You can say that, .Net core is a cross-platform implementation of .Net framework.

Why .Net Core?

  • It is a framework to build web applications 
  • It is open source 
  • Deploy .Net core application to on-premises or to the cloud
  • Build and run the application on Windows, MAC and Linux 
  • A cloud-ready environment 
  • Ability to host in IIS or self-host
  • Use of Docker Containers
  • Implements Microservice Architecture
ASP.Net core apps can run on cross-platform such as Windows, Mac, Linux. So how can someone choose between .Net core and ASP.Net Framework.

Go for .Net core, if :

1. You are developing a cross-platform application.
2. You are looking for a high performance and scalable system.

Go for ASP.Net framework, if:

1. You are working on an environment that does not support .NET core.
2. NuGet packages not available for .NET Core.

.Net Core Tools

1. Visual Studio 2015/2017
2. Command Line Interface 

How to start development with .Net Core in Visual Studio 2015?

If you are using VS 2017 you will get .Net Core in installed template. And if you are using VS 2015 then you need Update 3 of VS 2015.
Follow below steps to update Visual Studio 2015 to start development with ASP.Net Core 1.0.1.

Open Visual Studio 2015. Tools ->Extensions and Update

You will see “Microsoft ASP.NET and Web Tools”, click on Update.

what is .net core

You will see Microsoft .NET Core 1.0.1 installer.

.net core

Install this tool.
Once installation was done, Open VS 2015
Go and create a new project, and you will see .NET Core in the template.


See below screen for more details.You can notice the message in right side saying –
“Project templates for creating ASP.NET Core applications for Windows, Linux and OS X using .NET Core.”

.net core

Create a Web Application, and you will see below welcome page.

introduction to .net core

ASP.Net Core Project layout

.net core 1.0

.Net Core with Visual Studio 2017

If you are using Visual Studio 2017 then you do not need an update, you can start development with .Net Core in Visual Studio 2017.

You can download Community Edition which is free to use for the individual.

Create a new project in Visual Studio 2017 and select ASP.Net Core Web Application.



Select your desired Project Template.



Once you create the project, solution explorer look like this. It is quite similar to what we have seen in Visual Studio 2015.

Application Settings (appsettings.json)

appsettings.json file contains all application's settings.  It holds different configuration settings for the different environment like development, staging, UAT, production.

Above screen shot was taken from local PC that's the reason it is showing appsettings.Developmen.json

Startup.cs

This file contains 2 important methods.

ConfigureServices() and Configure()

ConfigureServices() - This method gets called by the runtime. Use this method to add services to the container.


public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
        }


Configure() - This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }

            app.UseStaticFiles();

            app.UseMvc();
        }


So you can start the development with .Net Core in Visual Studio 2017 and Visual Studio 2015 as well.

A lot of stuff on .Net Core will be coming on my blog. Keep your eyes on SharePointCafe.Net

Summary:

1. .Net Core is a framework to build web applications.
2. .Net Core is cross-platform
3. .Net Core is easy to implement Microservice Architecture
4. Use of Docker containers is easy.
5. Till the publishing of this blog .Net Core 2.0 is the latest version


Next Blog - Introduction to .Net Core 2.0

Enjoy development using .NET Core.

Comments

Popular

What's new in C# 6.0 language - All new features of C# 6.0 for developers

SharePoint Interview Questions and Answers