ASP.NET Core 1.0 Setup and Hello World


facebooktwittergoogle_pluslinkedinmail

Recent release of ASP.NET Core 1.0 is very promising. It’s all open source and cross-platform. So let’s try to create something!

Integrated Development Environment

My favorite IDE is Visual Studio and I’ll be using Visual Studio 2015 Community edition (free). If you want to go cross-platform you can consider Visual Studio Code that works with Mac OS and Linux. You can get both here – download Visual Studio.

It’s also recommended to install latest update – Visual Studio 2015 Update 3. Here is direct VS Update 3 download link.

vs-2015-update-3

Please remember to upgrade NuGet Manager extension to the latest version as well.

nuget-manager-extension

.NET Core 1.0

The next step is installation of .NET Core. The easiest way to install, is to use the MSI. But if you’re not working on Windows machine you can use alternative installers. You can find all on .NET Core website. Here is direct link to MSI installer of .NET Core 1.0.

net-core-installer

ASP.NET Core Hello World

Finally, the most interesting piece. Open Visual Studio and create new project. Use ‘.NET Core’ category and ‘ASP.NET Core Web Application’ template.

Create-ASP-NET-Core-project

Next select ‘Empty’ template.

asp-core-select-empty-template

Finally, run the application (F5) and you should see following.

asp-core-run-hello-world

Let’s have a look at the project to see how it happened. Please have a look at Solution Explorer.

asp-net-core-solution-explorer

You should see Startup.cs file with following content.

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 AspNetCoreHelloWorld
{
    public class Startup
    {
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        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!");
            });
        }
    }
}

What it does? It just returns ‘Hello World!’ string for every request.

facebooktwittergoogle_pluslinkedinmail

Leave a comment

Your email address will not be published. Required fields are marked *