Hello World on .NET Core

The developments over the last few months in the data community had brought us to an interesting place. We’re going to have SQL on Linux and now we also have .NET on Linux too! While the implications of this are unclear, and worthy of significant prognostication…I’m going to take this time to show you how to get started with .NET Core on a Redhat Enterprise Linux Based System.

First up you’re going to need Redhat Enterprise Linux. The Redhat Developer Suite, now includes a free license of RHEL go get it on Redhat’s site.

Getting Started with Hello World

Once RHEL is installed, the first thing you need to do is enable the .NET repository. On a RHEL system, a repository is a collection of RPMs that can be installed on your computer. RPM is simply a software packaging mechanism that allows you to easily install, uninstall or upgrade software on your computer. So to enable the repository, we use a command named subscription manager to do that for us.

All we did there was enable the repository, which gives us access to the software in that repository, let’s go ahead and actually install .NET Core now. .NET Core leverages Software Collections to help manage concurrent versions of software on a system. So we’ll need to install scl-utils too. To do that that we use yum which will search the enabled repositories on our system and install the rpms specified and all of their dependencies.

Now let’s use scl to hop into the .NET programming environment. This is going to take you into another bash shell with specific environment settings for developing in .NET Core.

Let’s create a directory for our hello world application live in and change into it…

The command used to interact with .NET is simply dotnet. It has several parameters for .NET program management. First up, for our demo is creating a new .NET project, to do that we use the command dotnet new. This command creates a basic project definition in project.json and will create a file Program.cs in the current working directory. Program.cs will already have the code for our Hello World app, easy right? So let’s go ahead and run that command and get everything started.

Output:

Created new C# project in /root/HelloWorld.

 

With our project and files in place we need to tell .NET Core to load any dependencies for the project. This also places a lock on the project. If you skip this step, the next step will fail.

Output:

log  : Restoring packages for /root/HelloWorld/project.json…

log  : Writing lock file to disk. Path: /root/HelloWorld/project.lock.json

log  : /root/HelloWorld/project.json

log  : Restore completed in 627ms.

Everything is in place let’s compile and execute our program

Output:

Project HelloWorld (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing

Compiling HelloWorld for .NETCoreApp,Version=v1.0

Compilation succeeded.

    0 Warning(s)

    0 Error(s)

Time elapsed 00:00:01.9394202

 

Hello World!

 

And that’s it, like I said…interesting times in the computer world right now. This convergence of technology titans will certainly lead us to some cool places.

Need More Help?

Need some help installing RHEL or want to learn how bash works? Check out my Pluralsight Course “Understanding and Using Essential Tools for Enterprise Linux 7

Contact Me

Twitter @nocentino
 
Did you like this post? If so, click here for to sign up for our newsletter to get more SQL goodness delivered right to your inbox!


References:
https://www.microsoft.com/net/core#redhat
https://access.redhat.com/documentation/en/net-core/1.0/getting-started-guide/chapter-1-install-net-core-100-on-red-hat-enterprise-linux

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.