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?

MarioDS
  • 12,895
  • 15
  • 65
  • 121

2 Answers2

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

Community
  • 1
  • 1
Jochen
  • 1,488
  • 16
  • 21
  • 1
    what happen if i remove it from the web.config in my server ? – mejiamanuel57 Aug 12 '16 at 15:17
  • @mejiamanuel57 your site will use the IIS app.config for all settings – GoldBishop May 15 '18 at 01:24
  • Is Razor something that's compiled dynamically? – Sheldor the conqueror Jan 20 '22 at 19:23
  • 1
    @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). – Dai Feb 28 '23 at 03:57
  • 1
    @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 https://learn.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation ) – Dai Feb 28 '23 at 03:59
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:

Janis Veinbergs
  • 6,907
  • 5
  • 48
  • 78