Why isn't a compilation needed when updating cshtml files with .net code?

前端 未结 2 1084
离开以前
离开以前 2021-02-14 11:08

I\'m using Asp.net Mvc and I wanted to know why I don\'t need to compile my project when updating .net code in cshtml files? Now if we are talking about html\\css updates then I

相关标签:
2条回答
  • 2021-02-14 11:40

    Part of the ASP.NET infrastructure is the ASP.NET compiler. It is responsible for compiling declarative resources (*.aspx, *.ascx, *.cshtml etc.) into executable code.

    There is no magic, the runtime decides when to run the compiler (e.g. when the resource has been changed since last run) and then invokes the compiler to create an imperative code out of the declarative code (e.g. an *.aspx is compiled into *.cs). Then it invokes regular language compiler to get a *.dll containing CIL.

    This takes some time for the first time a resource is accessed, it could be handy to precompile all declarative resources ahead of time.

    Overview:

    http://msdn.microsoft.com/en-us/library/vstudio/ms178466(v=vs.100).aspx

    Precompilation:

    http://msdn.microsoft.com/en-us/library/aa983464(v=vs.110).aspx

    0 讨论(0)
  • 2021-02-14 11:50

    .cshtml files will be compiled just-in-time, that is when a request arrives regarding those pages.

    However controllers are pre-compiled and stored into your project's DLL files.

    Deciding which one to use, depends on your needs. Pre-compiling gives you less response time (because you've compiled the code before) but just-in-time compiling offers you flexibility.

    0 讨论(0)
提交回复
热议问题