Precompiling websites

When deploying a website, you have the option of precompiling the web project before you place it on a server. This compiles the project’s code into assemblies, which provides several advantages:

  • Faster initial response times - resources do not need to be compiled dynamically when they are requested for the first time.
  • Source code protection - you can create a compiled version of the website without any accessible source code.

Limitations of precompiled websites

Only use precompilation to deploy completed websites. Precompiled instances of Kentico have limited website development features.

You cannot edit, create or import virtual objects that contain ASP.NET markup and require compilation:

If you wish to import physical files that require compilation (such as cs, vb, aspx, ascx), you need to run the import process on the original project, and then create the precompiled site again.

Partial caching (i.e. caching portions of page output generated by specific web parts or controls) is not supported on precompiled websites.

Testing the website before compilation

You can check that your site’s virtual objects compile correctly before starting the precompilation. 

  1. In the Kentico administration interface, open the System application.
  2. Select the Virtual objects tab.
  3. Click Test virtual objects.

The system compiles all virtual objects and adds them to the temporary files in the application’s ASP.NET cache. This operation may take a long time, depending on the number of virtual objects in the system.

If the process finishes without errors, your website should run correctly after the precompilation.

Precompiling web projects

  1. In the Kentico administration interface, open the System application.
  2. Select the Virtual objects tab.
  3. Click Store all virtual objects in file system.
    • This saves all virtual objects into the web project as physical files, so they can be included in the precompilation.
    • On web application projects, you need to manually include the CMSVirtualFiles folder into the CMSApp project. See Deployment mode for virtual objects for details.
  4. Open your web project in Visual Studio (using the WebSite.sln or WebApp.sln file).
  5. Right-click the Kentico project in the Solution Explorer and select Publish Web Site.
  6. Prepare a publish profile according to your requirements. See How to: Deploy a Web Project for details.
  7. On the Settings tab, expand File Publish Options and select Precompile during publishing.
    • Click Configure next to the check box and choose the compilation mode (Allow precompiled site to be updatable):
      • checked - compiles the code behind of all web forms and controls, but stores the markup files (.aspx, .ascx) in their original code form.
      • unchecked - the compilation also includes markup files. The website contains only empty “stub” .aspx/.ascx files without any code.

    We generally recommend using non-updatable sites for optimal performance.

    • In the Merge options section, select the Do not merge. Create a separate assembly for each page and control option.
  8. Publish the site.

Alternatively, you can use command line tools to perform the precompilation and merging of assemblies:

Moving the database

You may need to copy the database to the server using the standard backup/restore procedure, since the compiled website cannot be used to install an SQL Server database. Other options are:

  • Install a non-compiled website on the server first, go through the setup wizard and then replace the non-compiled files with compiled ones, while keeping the web.config file.
  • Install Kentico locally and run the database setup against the remote SQL Server on the live server.