Register: Register: https://goo.gl/80ubrN
I am considering version CentOS 7.1 in this example. You can read more details installation of .NET Core on various platforms here.
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
Command: sudo yum install libicu
Step 2. Download the dotnet.tar.gz file
Step 3. Create folder /opt/dotnet
Step 4. Extract dotnet.tar.gz to newly created folder /opt/dotnet
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/
Step 2: Create basic project environment
Check the folder (command: ls) to see if two files are created:
- 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.
- project.json – project file
Step 3: Restore Dependencies
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.
First, make sure you have (at the time of writing this article) below prerequisites already:
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.
Click Ok, and you may wait for sometime to finish installing the packages.
Step 2: Display “Hello World”
Step 3: Execute the Program
Step 4: Publish the Project
- If this is your first time publishing, you will be asked to choose a publish target.
- Type a profile name and click OK.
Step 5: Execute the Published application
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
Step 2: Initialize a basic .NET project
- 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.
- project.json – the project file
Step 3: Restore the dependencies
Step 4: Compile and Run the project
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.