What exactly does <system.codedom>/<compilers> do in web.config in MVC 5?
Asked Answered
M

2

40

I am about to migrate a bunch of projects from .NET 4.0 + MVC 3 to .NET 4.5.2 + MVC5.

To make this easier, I've created a new blank MVC project to compare DLL references and some other stuff such as web.config.

In the latter, the following entries are generated by Visual Studio:

<system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
</system.codedom>

But I don't know what this does exactly. The MVC 3 projects don't contain these parts. My understanding is it has something to do with Roslyn?

Mapes answered 31/12, 2015 at 11:6 Comment(0)
A
53

These settings are used for dynamic compilation. They can be safely removed from the web.config if you do pre-compilation and only put the compiled assemblies on the webserver.

See also The impact of multiple compiler definitions in system.codedom in web.config

Arundel answered 31/12, 2015 at 11:12 Comment(5)
what happen if i remove it from the web.config in my server ?Oralla
@mejiamanuel57 your site will use the IIS app.config for all settingsSchoenfelder
Is Razor something that's compiled dynamically?Detent
@Sheldortheconqueror This question (and this answer) only applies to .aspx/.ascx files used in ASP.NET WebForms. I believe that System.CodeDom is used by Razor in the earlier non-ASP.NET Core version of ASP.NET MVC, but it's entirely irrelevant to ASP.NET Core and beyond which does not use web.config, and I believe modern Razor ("RazorV4" internally at MSFT) uses Roslyn directly without going through CodeDom (hence why VB.NET's .vbhtml is not supported by ASP.NET Core anymore).Actinoid
@Sheldortheconqueror But in ASP.NET Core, Razor .cshtml files can be either precompiled (as part of a normal project build) or they can (still) be edited-and-compiled ("dynamic compilation" aka "runtime compilation") within a published website/web-application, but requires extra legwork (and Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation: see learn.microsoft.com/en-us/aspnet/core/mvc/views/… )Actinoid
S
0

These lines are added whenever you install Microsoft.CodeDom.Providers.DotNetCompilerPlatform nuget package.

It is for improved performance whether precompiling or dynamically compiling asp.net app, by using "Roslyn" compilation

In my case precompile went from 34mins to 13mins:

Stranglehold answered 19/5, 2023 at 14:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.