Introduction
In this article, I will explain how to install .NET Core tools preview for Visual Studio and how to print “Hello World” in the latest ASP.NET Core 1.0.
Step 1
First download Visual Studio 2015 with Update 3 through the link
click here.
Step 2
Go to Install .NET Core tools preview for Visual Studio. This .NET Core tools adds support for .NET Core projects in Visual Studio 2015.
Step 3
This is really interesting. Open Visual Studio 2015 and create new Project.
Open Templates – > Visual C# -> Click .NET Core Category and you can see “ASP.NET Core Web Application” template.
Step 4
Select Empty Templates ( based on your requirement ) in ASP.NET Core Templates Category if you are going to host the app in Microsoft Azure Service and check in the “Host in the cloud option”.
Step 5
Open “Startup.cs” class in “HelloWorldDotnetCore” project folder.
Step 6
We are creating mini middle ware Application, using lambda expression in “app.Run”. This piece of code is creating “Hello World”.
C# Code
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.Logging;
-
- namespace HelloWorldDotnetCore
- {
- public class Startup
- {
-
-
- public void ConfigureServices(IServiceCollection services)
- {
- }
-
-
- public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
- {
- loggerFactory.AddConsole();
-
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- }
- app.Run(async (context) =>
- {
- await context.Response.WriteAsync(" Hello World! ");
- });
-
- }
- }
- }
Output 1
Step 7
“app.run” doesn’t work in .NET Core followed by using “app.Use”. It will pass two parameters and add the next middleware content In .NET Core.
C# Code
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.Logging;
-
- namespace HelloWorldDotnetCore
- {
- public class Startup
- {
-
-
- public void ConfigureServices(IServiceCollection services)
- {
- }
-
-
- public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
- {
- loggerFactory.AddConsole();
-
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- }
- app.Use(async (context, next) =>
- {
- await context.Response.WriteAsync("Hello World!!");
- await next();
- });
-
- app.Run(async (context) =>
- {
- await context.Response.WriteAsync(" Welcome to Dotnet Core ");
- });
-
- }
- }
- }
Output 2
Reference
Conclusion
We learned how to Install .NET Core tools preview for Visual Studio and how to print “Hello World” in the latest ASP.NET Core 1.0.