Speeding up build times in ASP.NET

2019-02-02 16:43发布

问题:

I am currently involved in a ASP.NET project with about 40 projects in the solution. We are doing all our development in cloned Virtual PC environments so all developers have identical setups. That's all good, managing dependencies is easy, however building the solution is horribly slow. Virtual PC can only utilize one CPU so I'm really only using half of my computers resources.

It takes a full 3 minutes from build to a complete page load.. and it's getting worse every day as the projects grow. Fixing simple things is starting to take a long time and personally, I'm getting frustrated waiting all the time as I can't really work while the computer is compiling.

Is there any way of distributing my build across several computers to speed up the build process?

Would an SSD noticeably improve upon my build times?

Are there any other way of speeding up the build?

Note: I have tried precompiling static dependencies with ngen but later read that ASP.NET does not support ngen. I use Visual Studio 2008 and there is no antivirus software present in the virtual environment.

回答1:

You can greatly reduce the time you wait for a build with ASP.NET by doing the following:

  • Use the new "optimizeCompilations" flag. It will tell .NET to not rebuild the entire project just because you changed one project/dll. If you have 40 projects and you don't use this, every time you change a simple method in one project, .NET will try to compile all other projects and dlls. With the new flag (plus the installation of a hotfix) you will see a lot of increase overall performance during development. Check it out this blog post with details on how to speed up the build with this the optimizeCompilations flag: http://www.wagnerdanda.me/2009/11/optimizing-asp-net-build-time-with-dynamic-compilation-and-optimizecompilations/

Hope it helps!

Wagner Danda da Silva



回答2:

And here is another tip to speed up build times with ASP.NET:

  • If you have enough memory, create a RamDisk and point your ASP.NET Temporary Files to this ram-based disk. Check this blog post for more details on how to speed up the build time of ASP.NET projects with RamDisk: http://www.wagnerdanda.me/2009/11/speeding-up-build-times-in-asp-net-with-ramdisk/

Hope it helps!

Wagner Danda da Silva



回答3:

Do you need to rebuild all 40 projects every time.

You can configure what gets built in the Solution Configuration settings.

I.e. if you're changes are only in your WebUI Project, and the other 39 projects are unchanged, you can create a build configuration where only your web application is rebuilt.

  • Look at the Configuration Drop Down
  • Click "Configuration Manager"
  • In the "Active Solution Configuration" drop down click "New"
  • Create a new Config copied from the Debug Configuration
  • In your new Configuration, uncheck all project builds except the ones you've made changes in


回答4:

Scott Gu has an fairly helpful post about this:

Tip/Trick: Optimizing ASP.NET 2.0 Web Project Build Performance with VS 2005

Scott also has another article on the speed of this Hard Disk, which also has an impact on the general performance of Visual Studio:

Tip/Trick: Hard Drive Speed and Visual Studio Performance



回答5:

Do not put so many projects in your solutions. Only create a new project when the code is run in a different process or on a different machine. There is no use to create so many projects in most cases. The number of projects is the most significant slow down in msbuild.



回答6:

You didn't mention your Visual Studio version, but if it's 2005 you might want to consider an upgrade to 2008. In my case this decreased build time on a largish (30+ projects) solution.

Another option it to pre-build a number of libraries that do not change anymore and reference the compiled dll's in stead of the projects.



回答7:

We have a similar situation, and I found that our virtual machines were being heavily throttled, and so although they each ran on a single CPU, they weren't allowed to fully utilise that CPU. I managed to get 3 virtuals running on one physical to all perform 100% faster.


I'd also look at trying to reduce your number of projects. Our main solutions has 40 projefts, and I've been slowly consolidating these, and making sure new development fits in to existing projects where possible. The main culprits for this were webservices, where each had originally been created in a separate project. I am now adding all new webservices into a single project, and slowly moving the others across.



回答8:

You might also consider switching to VMware Workstation, which does utilize multiple processors. I'm currently using a setup with two two-processor VMs, and all four do get used.



回答9:

What we did at our company is to use file reference, so only the changed projects need to be built, and at any given time there is no more than 10 projects in my solution, mostly 2~3 gets built.

We also build our trunk for each check-in, and have batch file for developers to pull the most recent dlls.

Of course, this doesn't stop the painful assembly reference error from happening, but they become more of a nuisance than problem after a while.



回答10:

Have you tried tuning up virtual PC?

http://www.windowsnetworking.com/articles_tutorials/Tuning-Virtual-PC-Performance.html

Old article but the gist is still correct.

I found, in a similar situation, that having a separate hard disk for the VPC disk images sped up performance remarkably especially when removing some of the throttling.

Maybe the problem isn't Visual Studio, it's just the fact that compilation is resource intensive.