.NET Core – Kick-start with “Hello World” in Linux/CentOS

I am considering version CentOS 7.1 in this example. You can read more details installation of .NET Core on various platforms here.
image_thumb6
I am using puTTY, a remote connection tool to connect to my CentOS VM.

Install and configure SDK

Step 1: Install Dependencies libunwind and libicu

If you are interested to know what are libunwind and libicu, please use google. Otherwise please just keep in mind that these libraries are required for the proper functioning of “dotnet” command.
Command: sudo yum install libunwind
image_thumb18
Command: sudo yum install libicu
image_thumb16

Step 2. Download the dotnet.tar.gz file

Command: curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=809131
image_thumb8

Step 3. Create folder /opt/dotnet

Command: sudo mkdir -p /opt/dotnet
image_thumb10

Step 4. Extract dotnet.tar.gz to newly created folder /opt/dotnet

Command: sudo tar zxf dotnet.tar.gz -C /opt/dotnet
image_thumb12

Create and Test “Hello World” program

Step 1: Create project folder

Create a folder and change the current folder to the newly created one. This is mainly to make sure we do not make unnecessary mess in the root or somewhere else.
Command: mkdir MyNETCoreTest
Command: cd MyNETCoreTest/
image_thumb14

Step 2: Create basic project environment

Apply command “dotnet new”. Since the command is not included in path, you might need to use the full path “/opt/dotnet/dotnet”.
image_thumb27

Check the folder (command: ls) to see if two files are created:

  1. program.cs – the project file. You may check the file contents. You can see a basic “Hello World” program with a Main() method. You can edit the file if wish. I have edited and added a new line.
  2. project.json – project file

image_thumb31
image_thumb33

Step 3: Restore Dependencies

Apply the command “dotnet restore”. This command will restore any necessary packages for the project. You can also see a new file “project.lock.json” also created.
image_thumb37

Step 4: Compile and Execute the program

Finally apply the command “dotnet run”. This command will compile the project – if this project is new, or if any files are modified. Then this will execute the program.

Happy Programming!

 

.NET Core – Kick-start with “Hello World” using Visual Studio

First, make sure you have (at the time of writing this article) below prerequisites already:

  1. Visual Studio 2015 Update 3
  2. .NET Core 1.0 for Visual Studio

I will not be explaining what is happening behind the screens or about the architecture whereabouts since this article is intended to be a kick start-with-the-technology article. I will be demonstrating a .NET Core console based application using Visual Studio 2015.
If everything is ready, let us start! 

Step 1: Create Project

On Visual Studio, create a new project via File → New → Project → Templates → Visual C# → .NET Core, then select the template “Console Application (.NET Core)
You will have to select the .NET framework version 4.5 or above to see the .NET Core specific templates. I will go with .NET Framework 4.6.1 for this example.
image

Click Ok, and you may wait for sometime to finish installing the packages.

Step 2: Display “Hello World”

Write your “Hello World” program. Here is mine:
image

Step 3: Execute the Program

Hit F5 or Run the program and confirm there are no errors.
Ok, mine is success:
image

Step 4: Publish the Project

Right click on the project in Solution Explorer then choose Publish…
image

  1. If this is your first time publishing, you will be asked to choose a publish target.
  2. Type a profile name and click OK.

image
Next, you can either click on “Next >” and modify connection or other settings or directly click “Publish

Step 5: Execute the Published application

Take command-line and navigate to your published folder. My folder looks like this:
image

Apply the command:
> dotnet <filename.dll>
image
Happy Programming!

 

.NET Core – Kick-start with “Hello World” using command line

This example demonstrates the creation of a .NET Core console application and execute it. Whereabouts of what is happening behind the screen and architecture will be discussed in upcoming articles.
Download .NET Core which is the prerequisite for this example should be present in your system. You can download it from here – https://www.microsoft.com/net/core

Step 1: Create a folder

Create a folder so that all your project files will be saved in one place.
image

Step 2: Initialize a basic .NET project

Use the command “dotnet new” to create a basic project.
image
You can see in the folder that two files are created.

  1. Program.cs – A “hello world” console application program. Check the source by opening in notepad or another editor. You can find the Main() method, which is the starting point of a console application in it.
  2. project.json – the project file

image
You can modify Program.cs if wish to experiment. I have added one more line in my example:
image

Step 3: Restore the dependencies

Apply the command “dotnet run” so that it will restore any project dependencies. Will be discussed in detail later.
image
You can see an additional file generated which is project.lock.json.
image

Step 4: Compile and Run the project

Finally, apply the command “dotnet run”. This command will compile the project, then executes it.
image

Note that, if it is a new .cs file, or if there are any modifications then you can see the compilation output in the console. Else it will skip the compile phase.

Happy Programming!