BT

Running .NET on Linux and Mac OS X

by Jeff Martin on May 04, 2015 |

The .NET Core runtime has realized the vision of being truly cross-platform with its arrival on Linux and Mac OS X.  Last week at Microsoft Build, Microsoft Program Manager Habib Heydarian discussed how this benefits developers and where they can start to explore these new opportunities.  In a talk titled “Taking .NET Cross Platform”, Heydarian began by explaining what a developer will see with a fresh installation of .NET Core.

First, all of the .NET code is contained in a single directory and it is not required to be installed in a system-wide location.  This lets each .NET application use a specific build if so desired.  Code compiled on Windows can run interchangeably on Mac OS X and Linux.

To run a standard HelloWorld program from the command line on one of these systems, use the following:

./corerun HelloWorld.exe
// corereun is a native host which runs the app
// On Windows, bootstrapping a .NET app is built into the OS

Using .NET on non-Windows platforms means that developers have access to ASP.NET 5, the CoreCLR, and benefit from the shared pieces:

  1. Runtime components
    1. 64-bit Just-in-Time (JIT) compiler and SIMD instructions
    2. Garbage collector
  2. Libraries
    1. Base class libraries
    2. NuGet packages
  3. Compilers
    1. .NET Compiler Platform (Roslyn)

How to obtain .NET Core

Mac OS X developers are encouraged to use Homebrew to acquire the necessary components.  Once Homebrew has been installed, the following commands will acquire the .NET pieces:

brew tap aspnet/dnx
brew update
brew install dnvm
dnx . kestrel

Linux users can acquire a TAR file that includes all the required pieces from the project website and then install them as follows:

tar zxvf PartsUnlimited-demo-app-linux.tar.gz -C ~/
source ~/.dnx/dnvm/dnvm.sh
dnvm use 1.0.0-beta5-11624 -r coreclr -arch x64
dnx . kestrel

You will notice that for both platforms the commands end with the execution of kestrel.  Kestrel is the “cross-platform web server for ASP.NET 5.”  DNVM is the .NET version manager.  At present, the project only supports 64-bit platforms on Linux and Mac OS X.  The team is still investigating how to add the ability to run on 32-bit systems. 

Joining Linux and Mac OS X, FreeBSD support has recently been added to the project.  One current limitation for all 3 platforms is that building .NET Core from source is limited to Windows.  To build .NET from source, a developer would need to start with CoreCLR and then they can build CoreFX.

Similar to how .NET developers on Windows can take advantage of Platform Invoke, on Linux developers can use the command DLL Import:

[DllImport(“libc”)]
private static extern int printf(string format);

Printf(“Hello, //BUILD 2015!\n”);

What’s next

Heydarian spent the reminder of his talk discussing what the team will be working on next and what Microsoft’s goals for the project are.  As Visual Studio continues to spread to non-Windows platforms, Microsoft would like for it to have improved debugging support for these new environments.  For VS2015 this means to have the ability to perform remote debugging.  For VS Code, this means starting with the addition of local debugging.

Another area for growth is improved overall production readiness.  To that end of the things team would like to do is incorporate MSBuild support and eliminate the current dependency on Mono to provide that functionality.

Heydarian says that Microsoft is making the following formal promises for .NET on Linux and Mac OS X when it is formally released and considered “RTM”:

  1. .NET Core apps can run in a production Linux environment including Docker on-prem and cloud
  2. Devlopers can edit compile debug their .NET code on Mac OS X using VS code or favorite editor
  3. Apps built using platform –agnostic feature have identical behavior on Windows and x-platform
  4. .NET Core brings along existing .NET cloud ecosystem of libraries to Linux
  5. Microsoft will support, service, and maintain .NET on Linux like any other Microsoft product

Adding Linux and Mac OS X support to your application

Microsoft will be making available an API Portability tool that can be used to analyzed existing code to see what assemblies are needed and what the platform target provides.  At present, the only Linux distribution tested for compatibility is Ubuntu 14.04.2 LTS.  While other Linux distributions are not specifically prevented, their ability to run the current builds is not guaranteed.

At present Heydarian views Microsoft’s version of .NET as fulfilling a different niche than Mono’s.  Haydarian says that “…while [Mono is] great for mobile scenarios, [it] wasn’t designed for server/cloud production-grade scenarios…”, thus the .NET Core is intended serve in server environments with high throughput, scalability, and a higher mean time to failure (MTTF). 

Developers looking to take advantage of the cross-platform future enabled by .NET should begin using and testing their application with the ASP.NET 5 project templates in VS2015RC and examine Parts Unlimited ASP.NET sample on GitHub.  Applications successfully working on Windows with ASP.NET 5 will be able to seamlessly move to Linux once .NET Core is deemed RTM.

Rate this Article

Relevance
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Never thought I'd see the day ... by Cameron Purdy

I'm looking forward to finding some time to try out the OSX port. I've used Mono in the past, but never would have suggested it for production use.

I'm also curious what the business model is here? For example, is Microsoft going to keep the various platforms up-to-date with Windows? And will it always be just the minimal "core", or will the entire platform eventually become cross-platform?

Peace,

Cameron.
For the sake of full disclosure, I work at Oracle. The opinions and views expressed in this post are my own, and do not necessarily reflect the opinions or views of my employer.

Re: Never thought I'd see the day ... by Geoff McElhanon

It's to expand the reach of their development tools and supported deployment environments, all to drive as much business to Azure as they can.

Re: Never thought I'd see the day ... by wakin imgen

I expect them (Microsoft) to keep the three supported platforms (Win/OS X/Linux) up-to-date, but not all Linux distro(s) though, it would be too much a hassle, maybe only Ubuntu, SUSE, Debian and Redhat. Although I do not expect them to port existing .NET UI stack such as WPF/Winforms over to other platforms, I do expect them to create a new cross platform UI stack using XAML. It's the logical next step.

Re: Never thought I'd see the day ... by Faisal Waris

Mono has also improved a lot. I have a Linux daemon running under mono (F#) that processes 10's of gigabytes / day (preps data for Hadoop insertion) that has yet to crash; it's been running for over a year.

The process was compiled as a windows service on Windows and then just moved over to Linux with the F# assembly. I use the 'mono-service' command to launch the packaged windows service as a daemon.

Early on I found that some methods that I was using were missing on mono so I had to work around them. That was it.

Installation instructions by Pablo Alberto Camino

Hi, just for those that came to this article looking for instructions on how to install .NET on MacOs know that the installation option using ,Homebrew has been deprecated and replaced by the installation package that you may find here or also at this alternative location

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

5 Discuss
General Feedback
Bugs
Advertising
Editorial
Marketing
InfoQ.com and all content copyright © 2006-2016 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT

We notice you’re using an ad blocker

We understand why you use ad blockers. However to keep InfoQ free we need your support. InfoQ will not provide your data to third parties without individual opt-in consent. We only work with advertisers relevant to our readers. Please consider whitelisting us.