Embrace the CLR

I’m working with .NET Core. It’s tres cool, but it bugged me that when you build an app, it generates an assembly file which using the dotnet utility to execute:

dotnet run <assembly name> [args...]

Having to use dotnet to execute the app struck me as kludgy, so I was happy to find notes on how to get a .NET Core project to construct a native executable. To create an executable that would run on 64-bit Windows 10, I used the following project.jsaon:

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "AgentLib": "1.0.0-*",
    "Microsoft.NETCore.App": {
      "version": "1.1.0"
    }
  },

  "frameworks": {
    "netcoreapp1.1": {
      "imports": "dnxcore50"
    }
  },
  "runtimes":{
    "win10-x64":{ }
  }
}

And BAM! Doing the build dropped an executable in bin\Debug\netcoreapp1.1\win10-x64. I did my happy dance, life was good.

But then I needed a 32-bit version of the app. And both 64 and 32 bit versions for Windows 7. And one for 64-bit CentOS 7.

Now the “runtimes” object looked like this:

  "runtimes":{
    "centos.7-x64":{ },
    "win7-x86":{ },
    "win7-x64":{ },
    "win10-x86":{ },
    "win10-x64":{ }
  }

…and here’s where I said “whoops!” ¬†That’s already plenty ugly, but it’s just for building on your development machine. Imagine the pain of deploying platform-specific executables!

At that point, it dawned on me that I was reiterating the work done by the runtime. If you install .NET Core, you get a dotnet command that runs on the system, and a CLR that can execute your .NET assemblies. Your assemblies will run wherever an appropriate CLR is installed, without rebuilding or reconfiguring.

In contrast, when you build an executable, you throw “write once, run anywhere” out the window.

I’m not saying that it’s always a bad idea to build an executable. If your app only needs to run on one platform, why not?

But if you need to support several platforms, or even run wherever .NET Core is installed, then you are better off letting the .NET development team handle the nitty gritty of platform specific deployment.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s