Precompilation in ASP.NET 2.0

Wednesday, June 22, 2005

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.


Comments
Andreas Kraus Friday, July 29, 2005
Hi,

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

http://www.sunlab.de/Tools.aspx
luc.gosso@teknomedia.se Tuesday, August 23, 2005
This is great but; Is there no posibility to deploy without loosing the Cache? without updating the /bin dir?
Andreas Kraus Wednesday, August 24, 2005
Sorry Luc, but I assume that's not possible.

Tool updated to v1.2
Zia Wednesday, September 14, 2005
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
scott Thursday, September 15, 2005
Yes Zia, you'll need the ASP.NET 2.0 runtime on the machine to view the files.
Adam Rogas Thursday, November 10, 2005
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 ?

scott Friday, November 11, 2005
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):

msdn.microsoft.com/.../default.aspx
Eric B Thursday, January 12, 2006
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?
christo Tuesday, January 17, 2006
Eric B

Got to the following folder

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

type aspnet_regiis -i
ken keane Friday, January 20, 2006
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?

ken keane Friday, January 20, 2006
Ref: my previous comment [mistake] I have published the code to a temp website on my server ozeoze.com

ken
Sasikumar Thursday, March 16, 2006
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.
Jullian Thursday, March 16, 2006
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?
scott Friday, March 17, 2006
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.
Christopher King Thursday, April 6, 2006
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
scott Thursday, April 6, 2006
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.
Christopher King Friday, April 7, 2006
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...
Max Friday, April 21, 2006
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
Geetha Monday, April 24, 2006
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
Paul Monday, April 24, 2006
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
scott Tuesday, April 25, 2006
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?
Geetha Tuesday, April 25, 2006
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.
Paul Thursday, April 27, 2006
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!
.net coder Friday, May 12, 2006
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.
Angry user Saturday, May 20, 2006
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...
Scott Saturday, May 20, 2006
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.

Damir Sunday, May 21, 2006
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.
Angry user Monday, May 22, 2006
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.
Ranga Wednesday, May 31, 2006
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

Erica Thursday, July 27, 2006
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.
scott Friday, July 28, 2006
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.
Erica Wednesday, August 2, 2006
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
Xiang Thursday, August 10, 2006
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
scott Friday, August 11, 2006
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:
msdn.microsoft.com/.../wdp/
Xiang Friday, August 11, 2006
Yes, thanks, Scott. The Web Deployment Project is what I need.
Maya Thursday, August 17, 2006
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.
scott Friday, August 18, 2006
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.
Venky Kris Tuesday, October 31, 2006
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 ?

admin Tuesday, October 31, 2006
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.
SobyZacharia Thursday, November 23, 2006
I ve created an application named forsalehomes.com using asp.net 2.0
where could i find forsalehomes.dll
Saravanan.R Wednesday, December 27, 2006
Thank you for helping me understand pre-compilation so simply and subtely.


par Wednesday, October 28, 2009
Hi scott,

i have been used precompilation method.i have faced an error & it is,
web.config(53): error ASPCONFIG: It is an error to use a section registered
as allowDefinition='MachineToApplication' beyond application level. This error
can be caused by a virtual directory not being configured as an application in I
IS.

so,what is the cause for this error?i have a bunch of projects which are contains group of modules & some of them contains webconfig file. so how can i solve this error?

somewhere i found to use LM/W3SVC/websitenum/ROOT/ path but it's not working.

early response is highly appreciate.

Thank You.
gravatar Scott Allen Wednesday, October 28, 2009
This is almost always because you are trying to compile a directory above the level where your root directory lives.

If you are trying to compile on the file system and you have multiple applications nested underneath a directory, then you'll have to switch to using IIS or move those applications into separated folders for compilation.

Hope that makes sense,
pe3 Monday, December 21, 2009
Hi All,

I've used the pre-compilation process to deploy a web site. After pre-compilation I got the .compiled and .dll files. I've copied all the files generated to the IIS folder in win 2003 r2, and when I browse the page I get the following exception:

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

I've pre-compiled with VS 2008, I've selected "use fixed naming and single paging..." and de-selected "allow this precompiled site to be updateable".

I appreciate any help.
Thanks in advance.
Regards.
gravatar Mario Sunday, April 4, 2010
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
i am italian please reply with example.
gravatar Mario Sunday, April 4, 2010
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
i am italian please reply with example.
gravatar ace virgel almario Tuesday, May 25, 2010
please help me,... why does my path of my compiled asp.net empty even though the compiler has done compiling with no errors encountered
gravatar Prakash Singh Monday, August 9, 2010
Hi,
Its a great article, i am a new developer so it is very knowledgeable for me.I want to know about a book for ASP.Net4.0,at present i m refering Apress(Mc Donald) and ASP.Net4.0(Kanjilal).
i will be thankful to you.
gravatar Zinnia Saturday, September 18, 2010
It is really very helpful.
Comments are now closed.
by K. Scott Allen K.Scott Allen
My Pluralsight Courses
The Podcast!