HelloWorld in .Net Core really takes less than 10 minutes!

Intro

I have been paying attention to the development of the .NET Core framework and the great features coming out of it. Things like cross-platform compatibility are very appealing and open a whole new window of opportunities to the developer community. I never decided to start experimenting with this until now, and since I saw how easy it was to setup, I decided to share my experience here. In this post I will list the required steps to write a HelloWorld console application using .NET Core framework. It literally took me less than 10 minutes to see “Hello World” in the output window!

Steps to create HelloWorld console application in .NET Core

1. Go to dot.net and download the .NET Core SDK

– Download and install .NET Core SDK for Windows
I am using Windows, but the same steps can be applied to Mac and Linux.

2. Open a command line

c:\Users\luis.carrazana\Documents>
I like Windows PowerShell, but you could use the windows command line, or Terminal if using a Mac.

3. Check if .NET Code SDK was successfully installed

Execute the following command:

c:\Users\luis.carrazana\Documents> dotnet
You should see something like this:
dotnetcore

4. Create a folder for the project and navigate to it

c:\Users\luis.carrazana\Documents> cd "MyProjects"
c:\Users\luis.carrazana\Documents\MyProjects> md "DotNetCore101"
c:\Users\luis.carrazana\Documents\MyProjects> cd "DotNetCore101"
c:\Users\luis.carrazana\Documents\MyProjects\DotNetCore101>

5. Create a new project

Execute the following command:

c:\Users\luis.carrazana\Documents\MyProjects\DotNetCore101> dotnet new
Two files should be created:
Program.cs  (contains the program logic).
project.json  (contains project configuration, including dependencies).
DotNetCore-dir.PNG
This is the simplest boilerplate for a console application, and it contains the required logic to print “Hello World” to the console.

6. Restore dependencies and prepare the project for execution

Execute the following command:

c:\Users\luis.carrazana\Documents\MyProjects\DotNetCore101> dotnet restore
DotNetCore_restore.PNG
This step generates a new file: project.lock.json
This file should not be touched or checked into source control. Its purpose is to cache the result of analyzing project dependencies, so it is faster the next time. More details abut this file here.

7. Run the program

Execute the following command:

c:\Users\luis.carrazana\Documents\MyProjects\DotNetCore101> dotnet run
The logic should get executed and the “Hellow World” message should be displayed.
dotnetcore-helloworld

That’s it! You have a full .NET Core program running.

Editing the program

The steps above are useful for setting up the minimal required infrastructure to execute .NET Core logic. From this point, you will certainly want to start choosing developer tools that will allow you to write code in a very efficient way.
You can choose any text editor (including Notepad), or you may wanna choose a more robust IDE to make the development workflow more efficient. Coming from a pure .NET background, my immediate choice is the lightweight Visual Studio Code, which offers some nice integrations and can be executed in Windows, Mac and Linux.
So to edit and extend this program, I would manually open Visual Studio Code and load the project folder. However, I learned a very useful tip from Scott Hanselman in one of his training videos: from the command line, type “code .” and it will open Visual Studio Code with the current folder already loaded, ready to go. Pretty neat.
c:\Users\luis.carrazana\Documents\MyProjects\DotNetCore101> code .

Summary

This post described the required steps to provision and execute a quick console application using .NET Core. This framework is currently in Preview mode, and any developer can start using it to write code and run it on any platform. Being a Consultant working for big enterprises, I don’t see myself leveraging this framework for production in the near future. However, it is a good idea to pay attention to the great amount of innovation coming out of it. This is opening up a whole new world for writing great applications.

Reference

Advertisements

Author: Luis Carrazana

Skilled Senior Technology Consultant and Strategist, with a decade of experience advising and assisting customers from small and large companies, including Fortune 500. Luis is a Microsoft Certified Professional with extensive experience in .NET framework and SharePoint development.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s