What are buildOptions and preserveCompilationContext used for?

Andrei picture Andrei · Jul 11, 2016 · Viewed 16.1k times · Source

I am playing with just released ASP.NET Core. I have created new project and I am looking at project.json. I'd like to know what is this part of configuration for:

"buildOptions": {
   "emitEntryPoint": true,
   "preserveCompilationContext": true
}

Answer

Nate Barbettini picture Nate Barbettini · Jul 11, 2016

emitEntryPoint is used to let the compiler know it's an application, not a library. In other words, if emitEntryPoint = true, you must have a public static void Main().

From the docs:

Creates an executable if set to true, otherwise the project will produce a .dll.

preserveCompilationContext isn't documented in the above page (yet), but it's required when you are using Razor or any other type of runtime compiling. Without it, runtime compilation of Razor views will fail.