本节书摘来自异步社区《圣殿祭司的ASP.NET4.0专家技术手册》一书中的第1章,第13节,作者: 奚江华,译者: 武海军 , 更多章节内容可以访问云栖社区“异步社区”公众号查看。
圣殿祭司的ASP.NET4.0专家技术手册ClientBuildManager类别提供编译ASP.NET应用程序的方法和属性,并提取产生的组件或产生的源代码。通过它可做预编译,而Aspnet_Compiler.exe命令背后正是ClientBuild- Manager类,但差别是ClientBuildManager类可以通过.NET程序来调用。
范例1-8 通过程序API执行编译工作在此,以程序调用ClientBuildManager类的编译API,执行网站的预编译,请参考ClientBuildAPI.aspx程序,如图1-45所示。具体步骤如下。
双击【预编译网站】按钮,加入编译程序:
01 sing System.Web.Compilation; //编译须引用这个命名空间 02 03 public partial class ClientBuildAPI : System.Web.UI.Page 04 { 05 //预编译 06 protected void btnCompiler_Click(object sender, EventArgs e) 07 { 08 ClientBuildManager cbm = new System.Web. ClientBuildManager(vdir,srcLocation,tarLocation); cbm.PrecompileApplication(); //预编译 10 * */ 11 12 if (!(String.IsNullOrEmpty(txtVirtualDir.Text) && String.IsNullOrEmpty(txtSourceLocation.Text) && String.IsNullOrEmpty(txtTargetLocation.Text))) { ClientBuildManager cbm = new ClientBuildManager(txtVirtualDir.Text, txtSourceLocation.Text, txtTargetLocation.Text); 15 cbm.PrecompileApplication(); //预编译 16 } 17 } 18 }在虚拟目录TextBox中输入“/VS2010IDE”。来源目录位置TextBox中输入“c:InetpubwwwrootVS2010IDE”。目标目录位置TextBox中输入“c:tmpVS2010IDE”。本文仅用于学习和交流目的,不代表异步社区观点。非商业转载请注明作译者、出处,并保留本文的原始链接。
相关资源:敏捷开发V1.0.pptx