title: Why are ASP.NET pages (both forms and MVC) dynamically compiled?
body: <p>There is a pattern in ASP.NET - whenever there is a piece of markup that generates code (like the <code>.aspx</code>/<code>.ascx</code> files in WebForms or <code>.cshtml</code> files in MVC3), these files are dynamically compiled at runtime. aspnet_compiler will produce another assembly for them, which references your code-behind assembly.</p>
  
  <p>This approach seems awkward to me and I don't understand why it hasn't been discontinued already. A much better approach (in my opinion) is like in Winforms or resource files - you have your <code>.whatever</code> file, and then there is <code>.whatever.desginer.cs</code> file. This designer file is created at runtime as you type. When you compile, the compiler doesn't care about your <code>.whatever</code> file, it just takes the <code>.whatever.designer.cs</code> file and produces a single solid assembly.</p>
  
  <p>This provides several benefits:</p>
  
  <ul>
  <li>You can inherit your forms from each other, similar to windows forms;</li>
  <li>You can always see the code that is being generated, possibly adjusting your markup to generate better code;</li>
  <li>You can easily instantiate strongly typed instances of your forms;</li>
  </ul>
  
  <p>The only benefit I can see from dynamic compilation is that</p>
  
  <ul>
  <li>You can change the markup file anytime and don't need to recompile the app.</li>
  </ul>
  
  <p>To be honest, I've often wanted for one of the first three benefits, but never for the last one. Recompiling the app to see your changes isn't that big of a deal. Especially since you have to do it anyway when working with code-behind, where the most of your time will be. And when you deliver your app to the client, you deliver it as a monolithic, precompiled block. When you update, you update everything, not just individual <code>.aspx</code> files - there's no point to.</p>
  
  <p>So... why is it like this? What am I missing?</p>