Publishing projects from Visual Studio
You can deploy Kentico web projects to your hosting server using the Visual Studio Publish function (MSDeploy).
- Decide whether to precompile the website prior to deployment. See the Precompiling websites section for more information.
- Open your web project in Visual Studio (using the WebSite.sln or WebApp.sln file).
- Right-click the Kentico project in the Solution Explorer and select Publish Web Site (web site projects) or Publish (web applications).
- Prepare a publish profile according to your requirements. See How to: Deploy a Web Project for details.
- Publish the site.
Visual Studio publishes the project according to your profile’s settings – either copies the project’s files to the target server or creates a deployment package.
Publishing web application projects
If you plan to publish from Visual Studio, we recommend installing Kentico projects with the web site configuration.
To use the Publish function of Visual Studio for Kentico web application projects, you need to sequentially publish all of the projects in the solution to the same target location:
- CMSApp
- CMSApp_AppCode
- CMSApp_MVC
After deploying the first project, make sure that your publish profile has the Delete all existing files prior to publish / Remove additional files at destination option disabled. You can configure the option in the Publish Web dialog in Settings -> File Publish Options.
Precompiling websites
When deploying websites from Visual Studio, you have the option of precompiling the web project before you place it on a server. This compiles the project’s code into assemblies, providing several advantages:
- Faster initial response times - the system does not need to compile resources 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:
- Page layouts (ASCX type)
- Transformations (ASCX type)
- Web part layouts
- Form layouts (ASCX type)
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 (Transformations, Page layouts, etc.) compile correctly before starting the precompilation.
- In the Kentico administration interface, open the System application.
- Select the Virtual objects tab.
- 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.
Preparing virtual objects for compilation
Before you start the deployment, you need to perform the following steps to include your website’s virtual objects into the precompiled project:
- In the Kentico administration interface, open the System application.
- Select the Virtual objects tab.
- Click Store all virtual objects in file system.
The system creates physical files containing the code of your virtual objects inside the project’s CMSVirtualFiles folder.
Note: On web application projects, you need to manually include the CMSVirtualFiles folder into the CMSApp project. See Deployment mode for virtual objects for details.
Enabling precompilation in your publish profile
When creating a publish profile for your Visual Studio deployment, configure the following precompilation options in the Publish Web dialog:
On the Settings tab, expand File Publish Options and enable Precompile during publishing.
Click Configure next to the Precompile during publishing check box.
Configure the options in the Advanced Precompile Settings dialog:
Allow precompiled site to be updatable:
- checked - compiles the code behind of all web forms and controls, but keeps the markup files (.aspx, .ascx) in their original form.
- not checked - the compilation also includes markup files. The precompiled website contains only empty “stub” .aspx/.ascx files without any code. We generally recommend using non-updatable sites for optimal performance.
Merge options - select one of the following options:
Do not merge
Do not merge. Create a separate assembly for each page and control
Do NOT select any of the other options. Merging of outputs into assemblies is not supported by Kentico projects.
After you finish setting up the profile’s remaining settings, you can Publish the precompiled site.
Tip: You can also use the ASP.NET Compilation Tool to perform the precompilation from the command line.
Moving the database
Precompiled Kentico sites cannot be used to install a new SQL database on the target server. If you need to move the database as part of the deployment process, you have several options:
- Copy the database to the target server using the standard backup/restore procedure and update the connection string in the project’s web.config file.
- Install Kentico locally without a database and run the database setup against the target SQL server.