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:

Runtime components 64-bit Just-in-Time (JIT) compiler and SIMD instructions Garbage collector Libraries Base class libraries NuGet packages Compilers .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!

”);

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”:

.NET Core apps can run in a production Linux environment including Docker on-prem and cloud Devlopers can edit compile debug their .NET code on Mac OS X using VS code or favorite editor Apps built using platform –agnostic feature have identical behavior on Windows and x-platform .NET Core brings along existing .NET cloud ecosystem of libraries to Linux 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.