Precompilation in ASP.NET 2.0

New article on OdeToCode: Precompilation in ASP.NET 2.0. Here is an excerpt:

Although pre-compilation will give our site a performance boost, the difference in speed will only be noticeable during the first request to each folder. Perhaps a more important benefit is the new deployment option made available by pre-compilation - the option to deploy a site without copying any of the original source code to the server. This includes the code and markup in aspx, ascx, and master files.

Other notes:

It seems the precompile.axd 'magic page' touted as a feature in the early days has slipped quietly into the bucket of dropped features.

Although pre-compilation allows you to deploy a web application without any ASPX files present, this still poses a problem if a request comes in for a directory and you want the request to find a default document for the directory. The 'default document' issue has been a thorn in the side of url-rewriters for quite some time.

If you try to pre-compile to a target directory that already contains a pre-compiled application, the aspnet_compiler will fail with “error ASPRUNTIME: Object reference not set to an instance of an object”. Ugh - unhelpful. Use the –f switch in this case to force an overwrite.

posted on Wednesday, June 22, 2005 12:05 AM by scott

Comments

Friday, July 29, 2005 1:41 AM by Andreas Kraus

# re: Precompilation in ASP.NET 2.0

Hi,

i wrote a small and easy deployment Tool for that matter. It always compiles by using -v:

http://www.sunlab.de/Tools.aspx
Tuesday, August 23, 2005 2:25 AM by luc.gosso@teknomedia.se

# Loosing the Cache

This is great but; Is there no posibility to deploy without loosing the Cache? without updating the /bin dir?
Wednesday, August 24, 2005 5:03 AM by Andreas Kraus

# re: Precompilation in ASP.NET 2.0

Sorry Luc, but I assume that's not possible.

Tool updated to v1.2
Wednesday, September 14, 2005 4:01 PM by Zia

# re: Precompilation in ASP.NET 2.0

Hi Scott,

First thig first, It is an excellent article and I thank you for making it so simple.

I downloaded Microsoft visual web developer, bcos it had asp.net version2. I did the "Pre-compilation For Deployment" option and copied the target directory into a staging machine. My staging machine still has asp.net version 1.1. I am not able to view the pages online. That is when I visit the pages I stored in the staging machine it gives the "Marker file" Infomation.
Do I have to do some setting on the IIS with respect to asp versioning.
Do I have to install Asp.Net version2 on the staging machine.
What am I doing wrong here?

Please help.
And thanks once again for an excellent article.

Regards,
zia
Wednesday, September 14, 2005 5:58 PM by scott

# re: Precompilation in ASP.NET 2.0

Yes Zia, you'll need the ASP.NET 2.0 runtime on the machine to view the files.
Wednesday, November 09, 2005 9:24 PM by Adam Rogas

# re: Precompilation in ASP.NET 2.0

Do you know of any process that will only "touch" changed files into the staging directory, using fixed names works great, but unless your copy utility is capable of looking for file diferences (CRC's) xcopy has to copy the entire bin directory over again anyways, because all of the dates on your recently compiled files are new.

Does any one have any idea's ?

Friday, November 11, 2005 6:34 AM by scott

# re: Precompilation in ASP.NET 2.0

I'm just going to start taking a look at the new web deployment project. I believe this will have that capability (I'm hoping):

http://msdn.microsoft.com/asp.net/reference/infrastructure/wdp/default.aspx
Thursday, January 12, 2006 1:38 AM by Eric B

# re: Precompilation in ASP.NET 2.0

I have tried to precomplie a site via VS 2005. I have copied to the web server all of the dll's in the bin directory and the aspx marker files. But when I navigate to one of the aspx pages all I get is the text inside the file.

Does anyone have any ideas as to what I am doing wrong?
Tuesday, January 17, 2006 5:25 AM by christo

# re: Precompilation in ASP.NET 2.0

Eric B

Got to the following folder

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

type aspnet_regiis -i
Thursday, January 19, 2006 8:40 PM by ken keane

# re: Precompilation in ASP.NET 2.0

I have just converted my site to asp.net 2.0 and published it to my server, works great!however i lost my original folder (virus).If I had copied it to my server I could copy it back to my development computer and start again: However when using publish to upload the website it is compiled. do I need to copy the folder and decompile it, or is there enother way I can contiue working on the website?

Thursday, January 19, 2006 8:48 PM by ken keane

# re: Precompilation in ASP.NET 2.0

Ref: my previous comment [mistake] I have published the code to a temp website on my server ozeoze.com

ken
Wednesday, March 15, 2006 9:47 PM by Sasikumar

# re: Precompilation in ASP.NET 2.0

Is there any way to give a custom name for my asp.net 2.0 application as in asp.net 1.x. And is there any to define "Default namespace" property in asp.net 2.0 applications.

Thanks and Regards,
Sasikumar.
Thursday, March 16, 2006 1:44 AM by Jullian

# re: Precompilation in ASP.NET 2.0

Hi ...
I think this article is great.
My only problem is that it does not work for me. I cannot figure out what I am doing wrong
since I do exactly as you demonstrated in this article, but all I get is an empty destination
folder!!! Please help. What am I doing wrong?
Friday, March 17, 2006 7:44 AM by scott

# re: Precompilation in ASP.NET 2.0

Jullian:

Try deleting the folders under the ASP.NET Temporary Files folder and trying again. I've heard this solves the problem for some people, although I've never seene this problem myself.
Thursday, April 06, 2006 12:59 PM by Christopher King

# re: Precompilation in ASP.NET 2.0

like many others on here have stated; nice article

that being said, why does the precompiler include my .sln, .resx, and the various visual source-safe files in the target/output directory?

it seems a bit strange that I have to delete this files manually before depoying them to the server...

thanx -- /chris
Thursday, April 06, 2006 1:40 PM by scott

# re: Precompilation in ASP.NET 2.0

Christopher: I've never seen that before. Are you using aspnet_compiler from the command line or the VS 'publish command'? In either case I'm not sure what to do about it - I've never had that happen.
Friday, April 07, 2006 9:06 AM by Christopher King

# re: Precompilation in ASP.NET 2.0

Thanks for the reply Scott.

Yes, I am using it from the command-line but from what I can recall the Publish command was doing the same thing.

I just posted a question in the dotnet.framework.aspnet newsgroup about this so maybe I'll get some help there...
Friday, April 21, 2006 2:23 PM by Max

# re: Precompilation in ASP.NET 2.0

I used aspnet_compiler for my asp.net 2.0 website - all ok in localhost but when I publish via ftp the response is: This is a marker file generated by the precompilation tool, and should not be deleted!
What is going wrong? thank you for answer
Hi
Monday, April 24, 2006 7:32 AM by Geetha

# re: Precompilation in ASP.NET 2.0

This is really a very good article.

I am stuck in the same place as some people already noticed here.
I have XCopied and trying to run the site. But it displays 'This is a marker file genreated by pre-compilation tool and should not be deleted.'

I am struggling to implement ASP.NEt 2.0 application on custom web server for a long time...But still.... Please give your suggestions.

Thank you
Geetha
grajasekaran@auanet.org
Monday, April 24, 2006 1:10 PM by Paul

# re: Precompilation in ASP.NET 2.0

Scott - this is excellent info. I've got a problem that I haven't seen before, though. I have a precompiled site that I've deployed to different webserver. Had no problem precompiling and installing on the server. Now I need to make a change to one of the pages. When I open the project, then try to rebuild or republish, I get this error:

Error 1 This application is already precompiled. /

How do I get the application to re-build or re-compile itself? The renamed dlls are in the /bin directory - do I need to get rid of those?

If it makes any difference, I'm using the VS "Publish" version of the precompiler.

Thanks!
Paul
pnoe@identitraktech.com
Monday, April 24, 2006 7:41 PM by scott

# re: Precompilation in ASP.NET 2.0

Paul: I think when you publish you'll need to select "allow web site to be updateble".

Geetha: Are you sure you have the virtual directory setup for ASP.NET 2.0 and not 1.1?
Tuesday, April 25, 2006 4:42 AM by Geetha

# re: Precompilation in ASP.NET 2.0

Scott, yes I have the Virtual Directory set up for ASP.NET 2.0.

This virtual directory is pointing to the target folder where the precomiled files are.
Any help please..

Thank you very much.
Thursday, April 27, 2006 1:50 PM by Paul

# re: Precompilation in ASP.NET 2.0

Scott - Yes, I'm 90% sure I had it set for updateable so that the html code would still be visible/editable. However, I looked in SourceSafe and the newly compiled .dlls are in the /bin directory in Sourcesafe now, when they weren't before the Precompilation.

Sorry for the delay, but I've been working in SQL 2005 Rptg Svcs for the last two days and haven't gotten back to VS 2005 since.

Thanks for any help you might be able to provide!
Friday, May 12, 2006 5:34 AM by .net coder

# re: Precompilation in ASP.NET 2.0

the article is gud n expalined in simple words.
now what if i have to deploy the application on one m/c n make it accessible fom other m/c. it works on Windows authentication...it gives me error in aunthentication.i m in the same domian.
Saturday, May 20, 2006 12:03 PM by Angry user

# re: Precompilation in ASP.NET 2.0

This VS version made me think for the first time to switch to Java.
First, there were some genial ideeas brought by the Delphi architect, hired by MS...."xcopy" was one of them.
Then Bill said that things need to be scrwed up, and they invented precompilation and other unnatural stuff...

The recent "Web application project" prooves that in the end, they realised what a huge mistake they made...
Saturday, May 20, 2006 3:05 PM by Scott

# re: Precompilation in ASP.NET 2.0

They did admit a mistake when they released Web Projects. Lots of people were asking for precompilation tools in 1.1. I don't see why it is unnatural.

Sunday, May 21, 2006 12:54 PM by Damir

# re: Precompilation in ASP.NET 2.0

I am getting error: "This application is already precompiled."

First, I was using the "Add web deployment proyect" and the additional setup project, then I removed them from the solution.

Now I cannot build my project :-(((

I agree with the rest of the people saying VS2005 is making us work more (bye bye productivity) just to have what we already had.

One dll per page that always changes its name? Oh my...

Thanks.
Monday, May 22, 2006 5:34 AM by Angry user

# ASP.NET 2.0 has gay approach

Hi Scott, thanks for answer, I was talking about precompilation as a limitation of xcopy deployment, (with assemblies), in the form it was in 1.1. I could remove the sources for publishing by deleting files etc...

MS often try to force things beyond their times, resulting unnatural features.
A professional will always want low level access to files to see what he is doing, I don't need fancy tools that masks operations...
I don't want my site dlls hidden deep in windows directory or somewhere else...

They tried to get rid of the old "DLL Hell", now they are making huge steps to create a bigger one.
Tuesday, May 30, 2006 10:23 PM by Ranga

# re: Precompilation in ASP.NET 2.0

Hi Scott,
I'm using VWE 2005 for my developments.
and i couldn't find "Publish Web Site" option in my IDE. Therefore, what I did was pre complied the application with aspnet_compiler.exe
then I moved and run the application once finished copying my files to the production server
But now i get this strange error.

" System.Web.HttpException: The file '/MyWeb/Default.aspx' has not been pre-compiled, and cannot be requested. "

No .asxp files have been changed after pre-complied.
Pls help me to solve this problem.

Thx & BR
Ranga

Thursday, July 27, 2006 9:18 AM by Erica

# re: Precompilation in ASP.NET 2.0

Scott,

Thanks for the excellent article. I have a quesiton and I was wondering if you have experience this.

I have vb code in the app_code directory. This vb code looks into the database to grab the masterpage. This allows user to make changes on the appearance on real time. If I don't compile the site, everything works. But if I compile it to the staging directory, it keeps telling me "The file '/user/staging/templates/test.master' does not exist.". It doesn't seemed like it understands the virtual path or it didn't do a full compile.

You have mentioned in your article that masterpages are compiled into the bin directory. Do you know if this is supported?

Ideas/thoughts are greatly appreciated.
Thursday, July 27, 2006 7:54 PM by scott

# re: Precompilation in ASP.NET 2.0

Erica:

You are using a VirtualPathProvider?

I'm pretty sure I've heard that pre-compilation does not work with VirtualPathProviders, it is something the ASP.NET team decided they couldn't support in time for the 2.0 release. I'm not 100% positive about this, but I'm pretty sure I've heard an MS person mention it once.
Tuesday, August 01, 2006 5:10 PM by Erica

# re: Precompilation in ASP.NET 2.0

Hi Scott,

Thanks for the reply. That saves me lots of time on the research. Yes, I am using VirtualPathProvider.

Have a great day!
Erica
Thursday, August 10, 2006 11:01 AM by Xiang

# re: Precompilation in ASP.NET 2.0

Hi Scott,

Thanks for the nice article. I am migrating my 1.1 web app to 2.0 and it seems to work fine until I'm trying to deploy the web app using 2.0. To my surprise, the web app does not produce .dll anymore. If we need to precompile for deployment, now we have to use this aspnet_compiler.exe. In VS2005 web deployment project does not have an easy way to deploy the compiled web dlls. Am I right? Or am I missing something there...

From your article and my experiening the VS2005, I conclude that we have to use the aspnet_compiler to precompile the website to dlls and then use the deploy project to collect files generated at the target directory that just got created by the aspnet_compiler to make the .msi. Is there an easier way to deploy web dll using the msi than what I just described?
I wonder such necessary step was not built in by VS2005 after all those fancy convienent GUI were added in VS2005.

Thanks,
frustrated user
Xiang
Thursday, August 10, 2006 7:14 PM by scott

# re: Precompilation in ASP.NET 2.0

Hi Xiang:

Yes, ASP.NET 2.0 is a bit different now. If you deploy all your .aspx and .cs/.vb files, ASP.NET can compile everything at runtime.

Another other options is to use the precompiler, or the "Publish" menu option in Visual Studio 2005.

Overall though, it sounds like you want to use the Web Deployment Project add-in:
http://msdn.microsoft.com/asp.net/reference/infrastructure/wdp/
Friday, August 11, 2006 7:26 AM by Xiang

# re: Precompilation in ASP.NET 2.0

Yes, thanks, Scott. The Web Deployment Project is what I need.
Thursday, August 17, 2006 1:15 PM by Maya

# re: Precompilation in ASP.NET 2.0

Scott, we are using Web Deployment Project to deploy a Web Service. The options that we are choosing are: Do not allow for update, create 1 dll, treat as library.
As a result of compilation, a whole set of files is produced. .resex files are included, as well as a solution file. I know I can delete those. The question that I have is how do I know, which files are not needed for the final deployment of the project. For example in the bin I have the following list of produced files: App_global.asax.compiled, App_WebReferences.compiled, ***.asmx.cdcab7d2.compiled, and ***.dll . I found out by experiment that I can safely delete App_global.asax.compiled and App_WebReferences.compiled (we are using web.config for web references). But as soon as I tried to delete ***.asmx.cdcab7d2.compiled and run withought it, the site crashed. I looked into the file and it looks like this:
<?xml version="1.0" encoding="utf-8"?>
<preserve resultType="2" virtualPath="/SomeName/SomeName.asmx" hash="fffffffff15c6deb" filehash="2e480ddbe903" flags="130000" assembly="SomeName" type="SomeName.SomeName">
<filedeps>
<filedep name="/SomeName/SomeName.asmx" />
</filedeps>
</preserve>

I also noticed that different development machines produce different filehash values. I deleted the hash and filehash keys out of the file, resaved the file and ran the site. The site was fine. So my question is this…. Is it safe to delete .compiled files out of bin? Should we be doing it? If we made a change to the Web Service, should we be replacing all files on the deployment machine, or just the dll?

Thank you.
Friday, August 18, 2006 9:19 AM by scott

# re: Precompilation in ASP.NET 2.0

Maya:

I'm pretty certain the asp.net runtime needs those compiled files when you have "do not allow updates". I'd deploy the entire set.
Tuesday, October 31, 2006 2:40 AM by Venky Kris

# re: Precompilation in ASP.NET 2.0

Hi,

One quick question. As per msdn one of the advantages of precompilation is that it protects the UI code from casual observation. But i guess u can still decomile them using professional tools.

Am i right ?

Tuesday, October 31, 2006 12:27 PM by admin

# re: Precompilation in ASP.NET 2.0

That is correct. Free tools can decompile .NET code, too.

With UI code it is a little different, because you don't get back the declarative markup. The job would be more difficult.
Thursday, November 23, 2006 3:07 AM by SobyZacharia

# re: Precompilation in ASP.NET 2.0

I ve created an application named forsalehomes.com using asp.net 2.0
where could i find forsalehomes.dll
Wednesday, December 27, 2006 3:04 AM by Saravanan.R

# re: Precompilation in ASP.NET 2.0

Thank you for helping me understand pre-compilation so simply and subtely.