Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of preserveCompilationContext under build option in project.json in ASP.NET Core App?

I am new to ASP.NET Core. I am trying to understand various options in project.json. But could not understand the meaning of preserveCompilationContext:true under build options in project.json. According to the microsoft documentation

it is described as follows:

preserveCompilationContext

Type: Boolean

true to preserve reference assemblies and other context data to allow for runtime compilation; otherwise, false

Thank you in advance

like image 390
manojkulkarni30 Avatar asked Nov 04 '16 15:11

manojkulkarni30


People also ask

What is PreserveCompilationContext?

PreserveCompilationContext is an MSBuild property that causes . NET Core projects to emit additional content to the application's dependency (. deps) file about how the app was compiled. This is primarily used to support run-time compilation scenarios.

What is DEPS JSON in .NET core?

deps. json will mean the host will blindly enumerate all . dll files in the application directory and use those as the "entire app". This typically means: Portable apps may not work (building with no RID specified will produce a portable app)

What can you do using the project JSON file for an ASP NET application?

In ASP.NET Core project. json is used for project metadata, compilation information, and dependencies. When used in other project systems, those three things are split into separate files and project.

Do you need DEPS JSON?

deps. json'. This file is required for functional tests to run properly. There should be a copy of the file on your source project bin folder.


1 Answers

As far as I know, this is primarily used for Razor pages. They are compiled at runtime, and the compiler needs access to reference assemblies, to make sure it compiles correctly. So, to use Razor pages, you need to set preserveCompilationContext, which then includes all the necessary files in the published output.

If you don't need runtime compilation, you don't have to set preserveCompilationContext.

like image 61
svick Avatar answered Oct 06 '22 22:10

svick