For a while now we’ve had the .NET Core, which is a cross-platform (Windows, Linux, MacOS) framework that allows you to write stuff in the C#
for example and afterwards run it wherever you like. Say what you will, but once you’ve tried Visual Studio it is a bit hard (at least for me) to go back to vim
for bigger projects.
So it sure sounds appealing to be able to write an app from the comfort of Visual Studio and know that it will work same way on my Linux boxes.
It even allows you to “publish” the app so that you can ship it without the end-user needing to install the .net framework on their machine.
That is great, in theory, but does it actually work and how does it look on Linux?
To answer that question I tested it on a clean Ubuntu 16 container.
There’s plenty of documentation and you can follow a quick start tutorial, to get a feeling for it.
Alternatively, this is my experience.
Start with installing the .NET Core SDK:
sudo apt-get install apt-transport-https sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial main" > /etc/apt/sources.list.d/dotnetdev.list' sudo apt-get update sudo apt-get install dotnet-sdk-2.1.4
Now, you can create your first super duper app:
mkdir doesitwork cd doesitwork/ dotnet new console
This will have created a simple HelloWorld console app, which you can build and run like so:
dotnet build dotnet run
That is it, it really is that simple.
Now, what about that “publishing” feature?
Say you want to distribute this beast of an app to other servers, you can build it for specific target distro like so:
dotnet publish --self-contained -r ubuntu.16.04-x64 -c Release
Now, go to bin/Release/netcoreapp2.0/ubuntu.16.04-x64
and see the wonder for yourself:
yes, the hell has frozen over, congrats, you now have DLL files on your Linux box. But it does work and you also have a full fledged ELF binary:
[fx@cf5859cd2ca8 ~/doesitwork/bin/Release/netcoreapp2.0/ubuntu.16.04-x64]$ file doesitwork doesitwork: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=b1e8f043daaa70349629d6129728a9891a19c89e, stripped
Sure, there are some nuances, like it trying to open 500+ files upon startup and in general doing 4K + system calls just for the hello world (strace
it and see for yourself). Not that anyone is counting of course.