.NET Core (or “No Hands” programming part 2)

Today we are going to create Hello World application without writing single line of code.
And we are going to create Hello World application on Windows but we will test in on Linux.

Java again you might think – think again. It’s a C# (c-sharp). But C# is Windows only you say.
Not any more, with the introduction of .NET Core you can create truly multi platform application with a C#.

First we need to install .NET Core SDK.
For Windows go to download page, download and install latest SDK.

For Linux it’s the same page to get the package, or you can use command line. Here is Ubuntu 18 example:

wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
sudo mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
wget -q https://packages.microsoft.com/config/ubuntu/18.04/prod.list 
sudo mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install dotnet-sdk-2.1.200

Now let’s ‘write’ our first program. Why write in quotes? Because we are not going to write anything.
Here is how it goes:
open Command Prompt (on any platform) and type

dotnet new console -o HelloDN
cd HelloDN
dotnet run

You should see “Hello, World” output. We are done – our first application with C# and .Net Core platform without typing anything.
Not to the second promise – run it on another platform.
First we need to create release version:

dotnet publish -f netcoreapp2.0 -c Release

now switch to ..\bin\Release\netcoreapp2.0\publish\, where you will find one exe, one pdb, and two json files.
Copy all of them to another machine (I build on Windows and run on Linux) and run

dotnet HelloDN.dll

Granted that you install .Net Core SDK on that computer as well you should see “Hello, World” output.
Isn’t that cool!?

Leave a Reply