Understanding ASP.NET compilation of web site projects
Here's how I understand asp.net compilation. Please correct any errors in my u开发者_开发技巧nderstanding.
If I do not publish a web site project, rather simply copy all the files to the web directory I know that the first visit it compiles and so the first visit it's a little slow. From then on (if I don't update the source) the website stays compiled correct (E.G. its not in a cache that expires)?
What if I update the source of a page, somehow ASP.NET detects a change and recompiles? Does it recompile just a single page or put everything in bin\MySiteName.dll?
Finally, if I publish a site I can't update the source code (aspx yes, but not code behind pages). This precompiles the site so the first load is quick. The site is forever compiled until a new publish.
You are right, the cache of a Web Site Project's assembly gets invalidated whenever you apply a change to a source code file. As stated in MSDN:
Any changes to a dynamically compiled file will automatically invalidate the file's cached compiled assembly and trigger recompilation of all affected resources. The next time a request to the code is made, ASP.NET recognizes that the code has changed and recompiles the affected resources of the Web application.
As far as I know there is no expire date attached to your assembly unless, of course, it gets deleted (assembly is stored in %WINDIR%\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\name_or_web_site).
Interesting note: with automatic compilation, it is important to leave debug=false inside your web.config file once you push your Web Site Project to production. If you forget it, batch compilation will be turned off and an assembly will be generated for every requested source page! You can read more about it on If broken it is, fix it you should's blog.
Here's an article that will help. It's a bit more then what you've stated but it should help you out.
Basically, I think you have it correct. The one thing I will tell you is that it is possible to precompile an ASP.NET application so that the first load is not so slow. Basically, you use aspnet_compiler.exe for this task. See http://msdn.microsoft.com/en-us/library/bb398860.aspx for more information than you will probably ever want.
精彩评论