5

When I deploy an ASP.NET project to the server which contains many ASCX files, the first page load can take a while presumably because the ASCX files are being compiled. Only the ones that are actually on the page are compiled though, so part of my deployment process is to navigate to a bunch of pages on the site. Once all pages have been navigated to, the site operates smoothly.

I would rather that ASP.NET compiles all those ASCX files immediately when I deploy, to remove this sloppy deployment step.

What is the best way to accomplish this?

tenfour
  • 36,141
  • 15
  • 83
  • 142

3 Answers3

4

Sounds like you're looking for ASP.NET Precompilation:

You can precompile a Web site project before it is made available to users. This provides many advantages, which include faster initial response time, error checking, source-code protection, and efficient deployment. This is particularly important in large sites where there are frequent changes in Web pages and code files.

You can also compile a project by using the Web application project model. In that model, all code files (standalone, code-behind, and class files) in the project are compiled into a single assembly and stored in the Bin directory. Because compilation creates a single assembly, you can specify attributes, such as assembly name and version. You can also specify the location of the output assembly if you do not want it to be in the Bin directory.

AakashM
  • 62,551
  • 17
  • 151
  • 186
2

If you convert your ASP.net website to a "web application", then you can deploy the compiled version. Right click on your website in solution explorer and click "convert to web application"

See ASP.NET Web Site or ASP.NET Web Application? for more details

Community
  • 1
  • 1
podiluska
  • 50,950
  • 7
  • 98
  • 104
  • Just a small note. As far as I can understand, .aspx and .ascx files will be compiled dynamically anyway, regardless it is a Web Application or Web Site project. [The source](http://msdn.microsoft.com/en-us/library/vstudio/aa983464%28v=vs.100%29.aspx). – Daniil Veriga Jul 23 '14 at 11:51
0

You can run msbuild on your Web solution and it will compile your code, then you can deploy the markup along the compiled .dll.

Sample NAnt script to do this:

<target name="determineMsbuildPath">
    <readregistry property="net.bin" key="SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0\MSBuildToolsPath"/>
</target>

<target name="msbuild" depends="determineMsbuildPath>
    <exec basedir="${net.bin}\" program="MSBuild.exe">
        <arg value="${solution}"/> <!-- put the path to your web solution here -->
        <arg value="/p:OutputPath=${workdir}"/>
    </exec>
</target>
Alvaro Rodriguez
  • 2,820
  • 2
  • 33
  • 38