开发者

PreCompile ASP.net mvc

I believe you can pre compile a asp.net mvc application but there are some issues with aspx files. Is it correct to say the view folder needs to be开发者_开发技巧 copied to the deployed location? If so does anyone know why? Thanks


The short answer is that ASPX (and ASCX) files don't get compiled and must be copied with your application when you deploy to IIS.

You can precompile an ASP.NET MVC application, but the ASPX/ASCX files don't get included in the mix. In our experience, we weren't able to use aspnet_compiler.exe to bundle everything into a binary, so we use csc (via nant) to compile all of the stuff that can be compiled, and then copy the rest. This includes the View folder.

If it helps, the relevant portion of one of our nant scripts is as follows:

(Assuming all dependencies have already been copied to the site folder's (BuildDir in this case) bin folder)

<csc target="library" output="${BuildDir}/bin/${FinalDeployDllName}.dll" >
  <references failonempty="true">
    <include name="${BuildDir}/bin/SomeDependency.dll" />
  </references>
  <sources>
    <include name="${BuildDir}/**/*.cs" />
  </sources>
</csc>

<copy todir="${target}" overwrite="true">
  <fileset basedir="${BuildDir}">
    <include name="**/*.???x" />
    <include name="**/*.js" />
    <include name="**/*.jpg" />
    <include name="**/*.jpeg" />        
    <include name="**/*.gif" />
    <include name="**/*.png" />
    <include name="**/*.html" />
    <include name="**/*.css" />
    <include name="**/*.swf" />
    <include name="**/*.Master" />
    <include name="**/Web.config" />
    <include name="images/**/*" />
    <include name="bin/**/*" />
    <include name="Content/**/*" />
  </fileset>
</copy>

<delete>
  <fileset>
    <include name="${target}/*.build" />
    <include name="${target}/*.scc" />
    <include name="${target}/*.sln" />
    <include name="${target}/*.suo" />
    <include name="${target}/build.*" />
    <include name="${target}/*.resharper" />
    <include name="${target}/*.resharper.user" />
    <include name="${target}/bin/*.xml" />
    <include name="${target}/bin/*.pdb" />
  </fileset>
</delete>

This'll create a folder at {target} with all the required files for deployment, to be packaged from there as you see fit.


I've always used Web Deployment Projects to precompile web applications and prepare them for deployment. Scott Guthrie has blogged about it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜