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:


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


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:


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