Devlico.Us
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @devlicious

Brendan Tompkins

Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 License.


Speed Up VS 2005 Web Development - Kick your App_Code Habit

Scott Guthrie talks about how to speed up build times for Visual Studio 2005.. It's a great read, and definitely something to know inside and out if you're doing ASP.NET development with VS 2005. You've got to hand it to a person in his position doing down and dirty blog posts to help us little guys out, from what I hear and from recent personal experience, he's very accessible.

In his post about build performance, he actually has a good nugget of wisdom about overall performance of the IDE as well. He mentions this:

Keep the number of files in your /app_code directory small.  If you end up having a lot of class files within this directory, I'd recommend you instead add a separate class library project to your VS solution and move these classes within that instead since class library projects compile faster than compiling classes using the /app_code directory. 

This will speed build time, but will also speed up your design time experience as well.  Why you ask? 

I recently spent some time on the phone with Bradley Bartz from MS, who explained this very slowly and patiently to me. I hope he'll let me know if this isn't right, but from my understanding, Every time you make a change to a file in the App_Code directory, this invalidates the Visual Studio's internal cache of classes in this folder. The very next time you try to open a designer for an ASPX page or ASCX control, VS has to re-compile this folder to get the metadata it needs for the design-time rendering of the control. This can cause the IDE to slow to a crawl.  One the classes are cached, things speed up significantly in the IDE.

This was a big eye opener for me.  I'd been using the App_Code folder as an easy way to get a globally accessible class in my web projects. If it was stuff that only was related to the current web site, I felt this was a good choice for where to put the code.  The problem was, I was banging up against this slowness all the time. I'd get some class designed, tab over to a page or control to do some databinding and find myself waiting in frustration, my development rhythm shot. Little did I know that I was waiting on a compilation of the entire App_Code folder. 

So, I'm going to seriously wean myself off of this folder, in favor of a separate dll project for these situations where I need a class to be visible across controls or pages.

-Brendan



Comments

Billy McCafferty said:

Great find Brendan...I've gotten so frustrated with web project builds that I only do it about once a week or whenever I add a new PageMethods method (even then, you can update PageList.xml manually).  (IMO, App_Code was a terrible thing to give developers for a number of reasons...some of which you touched on above.)  Between the tips listed in the article, and the latest 262 build of ReSharper, I'm (cautiously) optimistic about developing with VS.NET 2005.

# September 22, 2006 5:35 PM

Dave Bouwman said:

Any idea if there is a similar issue with user controls in WinForms apps? I've got one small app that has about 10 user controls, and it's a total dog in VS2005, but other apps which don't have as many or any user controls are reasonable.

Thanks for the article - I've googled on this and found relatively little.

# September 23, 2006 8:33 PM

Christopher Bennage said:

I have a large Web application that started out in .NET 1.1.  When we migrated to 2.0 (and VS 2005) compile times grew significantly , as well as the time it took for the designer to open.  Based on Scott's blog, I converted the application to a Web Application Project.  (See http://webproject.scottgu.com/)  This helped a lot with the compile time, though I still have problems with the designer. I haven't performed any experiments, but I suspect it may have something to do with the inordinate amount of custom controls involved in the project.

# September 24, 2006 12:53 AM

Dave Donaldson said:

+1 for the Web Application Project. Using this instead of a Web Site project *greatly* sped up build times in VS2005.

# September 24, 2006 6:05 PM

Joe Niland said:

I've also found the Web Application Project to be superior. Unfortunately I am also experiencing very slow performance when using the designer! In the current project I'm working on, we're not using app_code at all, having opted for the separate class library approach.

In order to handle global constants in the web tier, we've created a 'Web' class library separate from the Web UI project (the web app proejct). Web contains the global.asax.cs code-behind file and a constants file, which can be used across the Web tier.

Namespace wise we have:

Company.App.WebUI

referencing:

Company.App.Web

which contains:

the classes: Global (global.asax.cs) and Constants

In the master page within WebUI, we reference the Web namespace, thus giving all WebUI pages access to Global and Constants.

# September 26, 2006 5:53 AM

Brendan Tompkins said:

Joe,

This sounds like it couldn't get any simpler.   Like I said, beta 1 is supposed to fix many of the IDEs "Papercuts" that make it slow.

I'm looking forward to it.

# September 26, 2006 9:12 AM

Chris said:

Should this only be done for older VS2003 sites? I did this for my web application that I started in VS2005 and while it does build much quicker it seems that a re-build will always cause my session to end. Will this change the way I update my site now because it looks like it compiles one site-wide dll? Am I missing something?

Thanks for the cool post!

# October 24, 2006 11:20 AM

Shannon said:

This is very interesting, and I can't believe I hadn't figured it out sooner..  Reminds me of a project I had a while ago which was an absolute dog, this would have helped so much.

PS. I look forward to the day when we can somehow stop blog spamming, that's just ridiculous and really destroys the experience.

# July 20, 2007 7:27 AM

Scott’s Blog » App_Code: Best In (Very) Small Doses said:

Pingback from  Scott’s Blog » App_Code: Best In (Very) Small Doses

# November 6, 2007 3:30 PM

Ali said:

Hide the folders using windows explorer like App_Code, Images etc that u dont want to recompile again and again.

this will decrease the build time.

# October 27, 2008 4:43 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Brendan Tompkins

Brendan has been programming with .NET since the first public beta and is owner and operator of Port Technology Services, a consultancy company providing .NET application development services to the Maritime industry. In July, 2007, he was awarded the Microsoft MVP award for ASP.NET. He's also a proud co-founder of failed .COM startup Intrinsigo, and has had a hand in the failure of numerous other businesses. He currently runs CodeBetter.Com and Devlicio.us, and lives in Norfolk, Virgina with his wife Tiara and son Ian.

View Brendan's profile on LinkedIn

Check out Devlicio.us!

Our Sponsors

Proudly Partnered With