Pre-compilation (Publish function)

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  

If you want to pre-compile the web site before placing it on the live server, you can use Visual Studio's Publish function. It allows you to compile the source code into assemblies. This provides several advantages:

 

faster application start (no compilation is required)
intellectual property protection - if someone gets your web site code, he will not be able to read the source code easily
better security - the code cannot be easily modified by potential hacker

 

However, there's also a disadvantage: if you compile the web site, you will not be able to use some of the Kentico CMS features:

Import of the web site.
New site wizard.
You cannot add code in the Code tab of web parts (the Code tab is an obsolete feature as of Kentico CMS 3.0, it is mentioned here due to backward compatibility reasons).

 

If you run a pre-compiled web site, you will get the errors like:

 

The file '/CMSTransformations/cms/event/preview.ascx' does not exist.

 

This means that the system requires a virtual object, but the VirtualPathProvider is probably not running and cannot provide the system with that object.

 

 

Pre-compiling the Web Site

 

Please note that for building the pre-compiled web site, you have to rename Microsoft.Web.Services3.dll.rename file to Microsoft.Web.Services3.dll in ~\Bin directory.

 

Since the virtual provider cannot run in a pre-compiled web site, you need to store the physical files to the system before compilation. You can save all the virtual objects to the file system in CMS Site Manager -> Administration -> System -> Deployment interface by clicking the button “Save all virtual objects to disk”.

 

Please note that these files are just copies of the actual virtual object and will be used by the system only if the VirtualPathProvider cannot start. Also, the changes to the objects through the administration interface will not affect these files until you save all the objects to the disk again.

 

Then, you can use Build -> Publish item in Visual Studio main menu and pre-compile the web site. You will see a dialog like this:

 

devguide_clip0198

 

You need to enter the path outside your current web project where the compiled version will be placed. You can choose between two compilation modes using the Allow this precompiled site to be updatable checkbox:

 

Allow the site to be updatable (checked) - the code behind and app_code classes are compiled, but ASPX files are stored in their original source code form.
Do not allow the site to be updatable (unchecked) - the code behind and app_code, as well as ASPX files are compiled and the web site contains only empty "stub" ASPX files without any code.

 

We generally recommend that you do not allow the site to be updatable, since it provides the best performance.

 

 

 

Limitations

 

In the precompiled web site, the VirtualPathProvider is stopped automatically. When VirtualPathProvider is stopped, you cannot edit transformations and layouts through the user interface without saving them on the disk again.

 

You may need to copy the database to the server using the standard backup/restore operation since the compiled web site cannot be used for SQL Server database installation. Other options are:

 

to install a non-compiled web site 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 as is.
to install Kentico CMS web site locally and run the database setup against the remote SQL Server on the live server.

 

In the portal development model, you cannot use custom web part code (Web part properties –> Code tab). If you need to add custom code on the Code tab and run the web site in the compiled version, you need to create user controls, place web parts to the user controls and add your custom code to the web parts. Then, you can place the user controls to the page using the General/User control web part.

 

 

 

Testing the web site before compilation

 

If you wish to check if your web site runs without using VirtualPathProvider (to simulate the precompiled environment), you can disable the provider by adding the following key into the appSettings section of your web.config file:

<add key="CMSUseVirtualPathProvider" value="false" />

If your system runs with VirtualPathProvider disabled, you should be able to run it after the precompilation or deployment process.

 

Related topics: Configuration for Medium Trust environment, Deployment to the live server, Installation on shared hosting server

 

Page url: http://devnet.kentico.com/docs/devguide/index.html?pre_compilation_publishing.htm