|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
Publishing Web Sites
Visual Web Developer enables you to publish your Web sites, which compiles the site and copies the output to a location that you specify, such as a production server. Publishing accomplishes the following tasks:
Precompiles pages, source code in the App_Code folder, and so on, into executable output.
Writes the executable output to a target folder.
The Publish Web Site utility is not available in Visual Web Developer Express Edition.
Publishing a Web site offers the following advantages over simply copying the Web site to a target Web server:
The precompilation process finds any compilation errors and identifies the errors in the configuration file.
Initial response speed for individual pages is faster because the pages are already compiled. If you copy pages to a site instead of compiling them first, the pages are compiled on first request, and their compiled output is cached.
No program code is deployed with the site, which provides a measure of security for your files. You can publish the site with markup protection, which compiles .aspx files, or without markup protection, which copies .aspx files to the site as-is and allows you to change their layout after deployment.
If you publish an application that contains a reference to a custom component that is registered in the GAC, the component will not be published with the application. For more information, see.
For more information, see.
The first step in publishing is to precompile the Web site. Precompilation for publishing is somewhat different from precompiling in place (which is referred to in Visual Web Developer as building). Precompilation performs essentially the same compilation process that normally occurs when a page is compiled dynamically upon being requested in a browser. The precompiler produces assemblies from the pages, including both the markup and the code. It also compiles files in the App_Code, App_GlobalResources, App_LocalResources, and App_Themes folders.
You can compile both single-file ASP.NET pages and code-behind pages. For information about these two models, see.
Choosing between Precompilation and Building
The precompilation step in publishing differs from the compilation that occurs when you build a Web site while testing it. Building compiles the site, or the current page and any of its dependent files, and then runs it. The build process is a form of testing and does not produce output that you can deploy. In contrast, precompilation during publishing creates output in a specified folder that you can deploy to a production server.
Writing Precompilation Output
When the precompilation process is finished, the resulting output is written to a folder that you specify. You can write the output to any folder that is accessible to you in the file system, by using File Transfer Protocol (FTP), or across HTTP. You must have appropriate permissions to be able to write to the target site.
The publishing process deploys only the files in your Web site folders and subfolders. It does not deploy the Machine.config file. Therefore, the configuration of the target Web server might be different than it is on your computer, which might affect the behavior of your application.
You can specify a target folder on a staging server or production server, or you can write the output to a folder on your local computer. If you specify a folder on a production server, you can precompile and deploy in a single step. If you choose to write the output to a folder that is not part of a Web site, you can copy the output to the server in a separate step.
If you open a precompiled Web site using Visual Studio, you will not be able to build the Web site. Build options will be turned off. It is recommended that you edit the files in the original Web site, precompile the site, and publish it again.
The output of the compilation process includes the compiled assemblies for any code or pages. If you choose the option to allow the precompiled site to be updated, any code-behind classes for your .aspx, .asmx, and .ashx files are compiled into assemblies. However, the .aspx, .asmx, and .ashx files themselves are copied as-is to the target folder so that you can make changes to their layout after deploying the site. For precompiled sites that can be updated, the code in single-file pages is not compiled into an assembly, but is instead deployed as source code.
Static files are not compiled. Instead, they are copied as-is to the output folder. Static files include graphics, .htm or .html files, text files, and so on. For more information, see.
If an error occurs during precompilation, it is reported to you in the Output window and in the Error List window. Errors during precompilation will prevent the site from being compiled and published.