Jack Dermody

Compiling NET Core to Native

There's a tool called crossgen.exe that comes with the .NET Core framework that you can use to pre-compile your .NET Core application to avoid the initial JIT compile step.

This is not the compile to native that was briefly promised for .NET Core, but merely a step that promises to improve the first load experience.

The documentation doesn't go into much detail about how to make it happen, but it turns out to be straightforward.

The first step is to locate crossgen.exe. It gets installed into the global Nuget cache when you install the .NET Core SDK.

On my machine, the global nuget cache is:

C:\Users\Jack\.nuget\packages

and the Windows 7 x64 crossgen.exe was installed to:

C:\Users\Jack\.nuget\packages\runtime.win7-x64.Microsoft.NETCore.Runtime.CoreCLR\1.0.2\tools\

The second step is to find clrjit.dll which turns out to be a dependency of crossgen.exe. On my machine I found the corresponding clrjit.dll at:

C:\Users\Jack\.nuget\packages\runtime.win7-x64.Microsoft.NETCore.Jit\1.0.2\runtimes\win7-x64\native\clrjit.dll

Armed with these two paths we can create a batch file that pre-jits each of our application assemblies (after a .NET Core publish), along the following lines:

// for each fileā€¦ 
<<path to crossgen.exe>> -JITPath <<path to clrjit.dll>> /in "<<path to assembly>>" /out <<path to assembly with .ni(.dll|.exe) suffix>> /Platform_Assemblies_Paths <<path to folder that the application was published to>>