Building .Net core applications for different platforms

By | July 23, 2018

.Net core is actually very cool brainchild of Microsoft. It tries give you possibility to publish the same code to the multiple OS platforms. The result sometime looks cumbersome but probably it does not matter so far, if you want to migrate Windows code to Linux, Mac OSX and Android fast. Definitely it is not perfect so far. There may be a lot of exclusion exceptions which looks as PlatformNotSupportedException, when the .Net core code does not work for some specific platforms only. Here I want to present an example how to build Windows and Linux applications using the same .Net core project. Let us create .Net core c# console application in Visual Studio 2017:

The code:

Build it and execute. The execution result looks like:


C:\projects\getos\getos\bin\Debug\netcoreapp2.0>dotnet getos.dll
Operating system: Microsoft Windows NT 6.2.9200.0
C:\projects\getos\getos\bin\Debug\netcoreapp2.0>

Now rebuild the application for other OS platform, for example for Centos 7 x64, however Microsoft gives us a lot of different oppotunities. From directory where csproj file is located execute command:


dotnet publish -r centos.7-x64

When build is completed the result will be place bin\Debug\netcoreapp2.0\centos.7-x64\publish directory:

Prepare Centos 7 x64 machine for execution this program. Install there .Net core:

sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
sudo yum update
sudo yum install dotnet-sdk-2.1
sudo yum -y install libunwind.x86_64

Upload somewhere on this Linux machine content of bin\Debug\netcoreapp2.0\centos.7-x64\publish directory, totally more than 150 files.
Change mode of getos to executable:


# chmod 755 getos

and execute it:


[centos7-64]# ./getos
Operating system: Unix 3.10.0.514

Leave a Reply

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