Instead of copying all files to the target Website, you can precompile the Website. With precompiling, the assemblies are created before the files are copied to the target Website. This way, source files are not copied to the target Website.
In the next Try It Out, you publish the Web application from Chapter 19 using Visual Studio.
Try It Out – Precompiling a Website for Deployment
Open the Web application from Chapter 19 with Visual Studio.
Start the Visual Studio 2005 command prompt.
Create a new directory for the precompiled Website, e.g., c:/precompiledWeb.
In the Visual Studio command prompt enter this command:
aspnet_compiler –p c:/BegVCSharp/WebProgramming/EventRegistrationWeb –v / c:/precompiledWeb
The option –p references the physical path of the source files from the Website that should be precompiled. The option –v / specifies how root references within the Web pages should be resolved. The last option c:/precompiledWeb specifies the target path where the precompiled files should be stored.
After the publishing is completed, check the created files on the target site. You will find ASXP files, but when you check the content of these files, you'll find only this text:
This is a marker file generated by the precompilation tool, and should not be deleted!
You can find the generated assemblies in the bin directory. the bin directory contains XML files (with the extension .compiled) that map the ASPX files to assemblies. Each Web page will have one assembly with the file extension .dll.
Important | Precompiling Websites has the advantage that the source files are not copied to the target Website, which means that the Web administrator cannot change the source files on the server. |