Precompiling ASP.NET 2.0 websites
Posted by: Suprotim Agarwal ,
on 8/25/2007,
in
Category ASP.NET
Abstract: ASP.NET 2.0 provides the ability to precompile websites into binaries before deploying them to the server. This has been a desired feature in the past and in this article we will see how simple it is to do so using ASP.NET 2.0.
Precompiling ASP.NET 2.0 websites
ASP.NET 2.0 provides the ability to precompile websites into binaries before deploying them to the server. This has been a desired feature in the past and in this article we will see how simple it is to do so using ASP.NET 2.0.
When a page is first requested from the server, the page is compiled by ASP.NET and then served. Even though one may argue that it does not take a long time for the compilation process to execute, however for sites which are updated frequently, it could lead to some first-time overheads issues.
ASP.NET 2.0 introduces the option of precompiling your site. This offers the following advantages :
1. You do not need to deploy the source code to the server. The website is precompiled into binaries, which is then deployed to the server.
2. It allows you to identify bugs first hand, during compilation.
3. Makes the deployment process a lot easier as all your aspx pages, user controls etc. are compiled into binaries.
There are two ways in which we can precompile a website.
Precompiling websites through command-line
To precompile a website using the command line, follow these steps :
1. Navigate to the directory C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727.
2. Run the aspnet_compiler command in the command prompt by typing:
aspnet_compiler -p <physicalpath> -v / <targetPath>
For e.g. let us assume that your website ‘Sampleweb1’ is stored at ‘C:\Websites’. To compile this website, you will type the following at the command prompt :
aspnet_compiler – p C:\Websites\SampleWeb1 –v /MyFirstWebsite C:\Projects\Samples
where :
· C:\Websites\SampleWeb1 - is the physical path to your website
· /MyFirstWebsite – is the virtual directory used at runtime
· C:\Projects\Samples – is the destination directory.
3. After the command has been run, open the C:\Projects\Samples directory to find a bin directory with the .dll and .compiled files.
Note: All your images, .css, .htm etc are not compiled into binaries. They are just copied to the target folder.
Precompile and publish websites using Visual Studio 2005
To precompile and publish your website using Visual Studio, follow these steps:
1. Open your website using Visual Studio.
2. Go to the Build Menu > Publish Web Site.
3. You get a Publish Web Site dialog where you can specify the path to publish to. Clicking on the eplisis(…) gives you the option of choosing your website output to File System, IIS, FTP or a remote site.
4. Select your options in the dialog :
a. Allow this precompiled site to be updatable – This option allows you to change the markup and client side functionality of the .aspx pages. However you cannot access the server side code.
b. Use Fixed Naming And Single Page Assemblies – This option is not available for in place compilation. It turns off batch builds during precompilation to generate dll’s with fixed names.
c. Enable strong naming on precompiled assemblies – This option specifies that your assemblies are strong named using a key file or container.
5. Click Ok to compile and publish the website.
Conclusion
Well that was pretty easy huh! I see this precompilation feature to be more advantageous from a security perspective rather than the slight performance benefit it offers. The security perspective is that the precompilation feature protects your source code on the server and helps you identify compilation bugs, early hand.
This article has been editorially reviewed by Suprotim Agarwal.
C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.
We at DotNetCurry are very excited to announce The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).
Organized around concepts, this Book aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on the latest .NET Core 3.0, .NET Standard and C# 8.0 (final release) too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.
Click here to Explore the Table of Contents or Download Sample Chapters!
Was this article worth reading? Share it with fellow developers too. Thanks!
Suprotim Agarwal, MCSD, MCAD, MCDBA, MCSE, is the founder of
DotNetCurry,
DNC Magazine for Developers,
SQLServerCurry and
DevCurry. He has also authored a couple of books
51 Recipes using jQuery with ASP.NET Controls and
The Absolutely Awesome jQuery CookBook.
Suprotim has received the prestigious Microsoft MVP award for Sixteen consecutive years. In a professional capacity, he is the CEO of A2Z Knowledge Visuals Pvt Ltd, a digital group that offers Digital Marketing and Branding services to businesses, both in a start-up and enterprise environment.
Get in touch with him on Twitter @suprotimagarwal or at LinkedIn