Compilation in ASP.NET applications

First, let’s take a moment to revisit compilation in the context of ASP.NET applications. There are generally two types of compilation that typically take place in an ASP.NET application: project compilation, and runtime compilation.

Project compilation

This type of compilation is used by ASP.NET applications built using the project system approach, i.e. they have a .csproj/.vbproj file. Project compilation typically takes place in Visual Studio via the project system and msbuild. It compiles any C# or VB files in your project and produces an assembly in the project’s bin folder. This assembly is then deployed to your web server along with your application and is loaded by the ASP.NET runtime when your application starts. Note this assembly could also be built from the command line using msbuild directly, e.g. when on a continuous integration or build server.

Assets such as page, user control, and handler code-behind classes, controllers and embedded resources are built using project compilation. Typically the source code for these assets is not deployed to the server. Other asset types, including .aspx, .ascx, .ashx, .cshtml, and .vbhtml, are deployed to the server and built by the ASP.NET runtime itself using runtime compilation.

Runtime compilation

ASP.NET includes a full runtime compilation pipeline that compiles many of your application’s assets on the web server when the application is running (hence “runtime compilation). Even if you’re using the project compilation model detailed above, part of your application will be compiled using ASP.NET’s runtime compilation feature. If you’re using the “Web Site” model for your application (you chose File –> New Web Site… in Visual Studio and your application doesn’t have a .csproj/.vbproj file) your application is built exclusively using ASP.NET’s compilation system. In this model, your application will contain shared code files in the App_Code folder.

Page assets in your application such as .aspx, .ascx and .cshtml/.vbhtml files, are compiled in the following fashion:

  • The file is parsed and turned into CodeDOM using the configured build provider
  • The CodeDOM graph that represents the file is used to generate a string of C# or VB code using the configured CodeDOM provider (the code generation step)
  • The C# or VB code is then compiled into an assembly using the configured CodeDOM provider (the code compilation step)
  • The assembly is loaded into the application and optionally cached to disk in the Temporary ASP.NET Files folder

You can read more about ASP.NET’s compilation system on MSDN.

Runtime pre-compilation

To confuse matters slightly, you can elect to pre-compile the portions of your application that use the ASP.NET runtime compilation system before deployment, so that the compilation doesn’t take place at runtime. This is achieved using the ASP.NET Compilation Tool, aspnet_compiler.exe. This will produce assemblies that can be deployed along with your application in the bin folder and will remove the cost associated with compiling those assets when the application starts up. The tool is simply a wrapper around the runtime compilation feature and doesn’t use msbuild in any way. It will only compile the portions of your application that would’ve been compiled at runtime by ASP.NET, so if you’re using the project compilation model from above, you’ll still need to compile your application’s project using Visual Studio or msbuild.

You can read more about ASP.NET pre-compilation on MSDN.

ASP.NET’s compilation system的更多相关文章

  1. MVC 5.0 之奇葩错误-<类型“ASP._Page__ViewStart_cshtml”不从“System.Web.WebPages.StartPage”继承>

    在实际项目中,我们通常添加MVC项目会先添加一个MVC Empty 的项目,然后需要什么在往里面添加. 但是Empty项目里面只有一个路由注册,而且没有_ViewStart.cshtml文件需要自己添 ...

  2. asp.net mvc4 使用 System.Web.Optimization 对javascript和style的引入、代码合并和压缩的优化(ScriptBundle,StyleBundle,Bundling and Minification )

    Bundling and Minification两个单词对今天的内容有个比较好的总结. 问题所在 一. 在asp.net包括mvc项目中,引入js和css也许有人认为是个很容易和很简单操作的事情,v ...

  3. 【ASP.NET 问题】System.InvalidOperationException: 对象的当前状态使该操作无效 【大量表单数据提交】错误解决

    出现的问题描述: 当页面的数据量比较大时,出现异常,详细信息: System.InvalidOperationException: 对象的当前状态使该操作无效 问题的原因:出现这个异常的原因是因为微软 ...

  4. asp.net 发送邮件代码 System.Net.Mail

    前台页面 SendEmail.aspx 代码 using System.Net.Mail;using System.Net; <h2> 发送电子邮件演示 </h2> <t ...

  5. Asp.Net Core使用System.Drawing.Common部署到docker报错问题

    Asp.Net Core 2.1发布后,正式支持System.Drawing.Common绘图了,可以用来做一些图片验证码之类的功能.但是把网站部署到docker容器里运行会遇到很多问题,也是非常闹心 ...

  6. ASP.Net模拟用户 System.Security.Principal

    一.概述 在实际的项目开发中,我们可能会需要调用一些非托管程序,而有些非托管程序需要有更高的身份权限才能正确执行.本文介绍了如何让IIS承载的ASP.NET网站以特定的账户执行,比如Administr ...

  7. C# ASP.NET发送电子邮件System.Net.Mail

    1.补充知识 (1)POP3和SMTP服务器是什么? 简单点来说:POP3 用于接收电子邮件 ,SMTP 用于发送电子邮件. (1)POP3具体指什么? POP3(Post Office Protoc ...

  8. (asp.net MVC学习)System.Web.Mvc.HtmlHelper学习及使用

    在ASP.NET MVC框架中没有了自己的控件,页面显示完全就回到了写html代码的年代.还好在asp.net mvc框架中也有自带的HtmlHelper和UrlHelper两个帮助类.另外在MvcC ...

  9. (asp.net MVC学习)System.Web.Mvc.UrlHelper的学习与使用

    上一次学习了HtmlHelper帮助类,这次我们学习一下UrlHelper帮 助类,看类名也都知道这个类是用来帮我们生成URL在ASP.NET MVC应用程序中.让我们来看看该类给我们带来了哪些方便的 ...

随机推荐

  1. 安装Elastix-2.4版本

    首先,下载Elastix地址:http://www.elastix.org,下载里面的2.4版本 第一步:选择安装,Enter 选择语言,默认就行 选择us,默认 选择全部 选择默认分区,点击OK 配 ...

  2. 配置PHP,Apache

    安装完windows 2003 server以后,还是个裸机,在安装limesurvey总是会有些问题,还好,问题都解决了,下面讲下配置的步骤: 第一步:先装上apache服务 apache服务启动以 ...

  3. GSON使用笔记

    GSON简介 GSON是Google开发的Java API,用于转换Java对象和Json对象,我在这里将记录一下GSON的简单使用 下载GSON 我们可以在其github仓库中下载,也可以使用Mav ...

  4. length length()

    数组长度 length String 长度 length()

  5. Cobalt strike 第二节生成报告

    0x00前言: 上一节我们说了怎么连接到服务器 0x01生成报告: 首先打开Cobalt Strike 点击Cobalt Strike -> Preferences Preferences Pe ...

  6. 11_java之接口和多态

    01接口的概念 * A:接口的概念 接口是功能的集合,同样可看做是一种数据类型,是比抽象类更为抽象的”类”. 接口只描述所应该具备的方法,并没有具体实现,具体的实现由接口的实现类(相当于接口的子类)来 ...

  7. Proof for Floyd-Warshall's Shortest Path Derivation Algorithm Also Demonstrates the Hierarchical Path Construction Process

    (THIS BLOG WAS ORIGINALLY WRTITTEN IN CHINESE WITH LINK: http://www.cnblogs.com/waytofall/p/3732920. ...

  8. swagger报No operations defined in spec!

    突然发现项目的swagger报No operations defined in spec! SWAGGER_SCAN_BASE_PACKAGE 路径改变了! package com.redis.con ...

  9. 使用Vagrant创建多节点虚拟机集群

    摘要: 在前一篇博客中,我介绍了使用Vagrant快速创建虚拟机,但是所创建的只是单个虚拟机.这篇博客将介绍使用Vagrant创建多节点虚拟机集群,可以作为Hadoop,Spark以及Storm等分布 ...

  10. Eclipse 常用插件地址大全

    安装方式: 使用Eclipse 的自动升级功能,菜单栏选[ Help ]→[ install new Software]  点击[Add]按钮,在“ Name ”中填入“ name (填写一个自己喜欢 ...