asp.net core linux hello world

On Asp.Net Core 1.0 you can create cross-platform applications that will run without modifications in multiple operating systems and CPU’s.

Today we are going to create an Asp.Net Core 1.0 “Hello World” sample in Windows and run it in linux (Centos 7.1 x86_64).

First we start with the installation of .Net Core 1.0.

For Windows, browse to https://get.asp.net/ and download the installer. After running this installer you will be able to run .Net Core applications in Windows. The project templates will also be install in Visual Studio.

For Centos 7.1, follow this guide: http://docs.asp.net/en/latest/getting-started/installing-on-linux.html#installing-on-centos-7

 

Now start up Visual Studio 2015 and create a new project: visual-studio-2015-new-project

Select the “Empty” Asp.NET 5 template.visual-studio-2015-new-net-core-mvc-project

This will create a sample project that can run under IIS, IISExpress or even self-host using the Kestrel cross-platform web server.

This project creates a simple listener that responds to all requests with a simple “Hello World” string.

Running it in IISExpress and launching Chrome:

hello-world-chrome

Running it in Linux:

Clone the repository:

# git clone https://github.com/nimeshjm/dotnetcore-sample.git

 

Restore the packages:

# cd dotnetcore-sample/src/helloworld/
# dnu restore
Microsoft .NET Development Utility Mono-x64-1.0.0-rc1-16231

  CACHE https://api.nuget.org/v3/index.json
Restoring packages for /dotnetcore-sample/src/helloworld/project.json
Writing lock file /dotnetcore-sample/src/helloworld/project.lock.json
Restore complete, 1343ms elapsed

Feeds used:
    https://api.nuget.org/v3-flatcontainer/

 

Start the project using the self-hosting web server:

# dnx web

Hosting environment: Production
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

 

Browse the website:

# curl http://localhost:5000
Hello World

 

You can the sample repository at: https://github.com/nimeshjm/dotnetcore-sample

With this sample you can try out a simple asp.net core linux project.