Search code examples
.net-corenative-aot

Why does ilc.exe not find a suitable system module?


I am trying to introduce the .NET NativeAOT ilc.exe compiler into the build process of my compiler. For this, I am currently calling it with the following arguments:

ilc in.dll -o out.exe

To get access to a complete version of ilc.exe, I have built the .NET runtime from source. The build directory containing the tool also contains the full runtime needed for NativeAOT, including a 14 megabyte System.PrivateCoreLib.dll. Still, running the above command results in the following error message:

Error: System module System.Private.CoreLib does not exists. Make sure that you specify --systemmodule

What is the correct way of specifying the system module?


Solution

  • System.PrivateCoreLib.dll (and other references) are supplied as reference files with -r e.g.

    -r:C:\Users\xxxxx\.packages\runtime.browser-wasm.microsoft.dotnet.ilcompiler\9.0.0-preview.7.24406.1\sdk\System.Private.CoreLib.dll
    

    However there are a lot of references for a normal c# program and they are normally created automatically by the tooling. If you have the package downloaded you can look at Microsoft.NetCore.Native.targets and the WriteIlcRspFileForCompilation target to see how they are generated.