Click here to Skip to main content
15,867,594 members
Articles / Visual Studio

Speed up Visual Studio Builds

Rate me:
Please Sign up or sign in to vote.
4.98/5 (23 votes)
17 May 2011Ms-PL4 min read 104.8K   29   13
This post discusses how you can decrease build time

Recently I got involved in a big project where we had a single solution with approximately 100 projects.

Why 100 Projects in a Solution?

The reason for a 100 projects solution is that like in many modular systems these days, we have the following three tiers:

  1. A few core / common projects every project will use.
  2. A large amount of modules, independent of each other. This tier directly depends on tier 1.
  3. A few end-projects which load the different modules. This tier indirectly depends on tier 2.

image

So, yes, we could create several solutions with each tier compiling only when needed and using DLL reference instead of project references, but the amount of changes in all the tiers was still large enough and I’ve already seen this kind of build process fail miserably. So this was no go.

Build time took 15 minutes for the whole solution. Since we enforced a gated check-in policy in the company, this was really a pain point for the developers.

Note that the developers’ computers were strong enough, with 8GB ram, Intel Core i7 CPU and SSD disks.

So I started investigating what can be done to improve the situation.

Step 1: Build Projects in Parallel

Although the PC has 8 logical cores, the build system in Visual Studio 2010, when using C#, still uses only a single core! (Note: This is not the case in C++ build system.)

So after browsing the web, I found how you can manually trigger msbuild yourself as a Visual Studio external tool to compile your solution in parallel.

image

More details on how to set this up can be found in the following post by Scott Hanselman: http://www.hanselman.com/blog/HackParallelMSBuildsFromWithinTheVisualStudioIDE.aspx

After setting this up, I got an approximate build time of 10.2 minutes. Not bad for a few minutes of work! Also, got the following beautiful image out of my CPUs, where you can really see them at work:

image

Step 2: Beware of Copy Local = True

In our 100-projects solution, lots of projects reference each other, obviously. In addition to these references, we also reference several 3rd party components, practically from each module.

All the above caused that whenever we would compile the solution, over 4.5 GB of files were written. The majority (95%) of the writes were DLLs which were copied to the output folder of each project.

To check out how many writes are done in your compilation, check out this post.

Anyway, 4.5 GB takes a long time to write, even on an SSD drive.

So the next step was to eliminate those writes. To do this, we changed almost all of the “Copy local” settings in all the referenced DLLs from the default True to False. This will prevent the referenced DLLs to be copied to the output folder of each project.

image

Note: Some file names were blacked to protect the client’s properties.

In addition, we also changed the output folder of all the projects to a single folder, so all generated DLLs are copied to the one and only place where we actually run them. Doing so dropped the writes while compiling to under 200 MB, a huge time saver. Specifically, build time dropped to 7.5 minutes!

Step 3: Use RAM Disk

A RAM disk is a logical disk which resides entirely on the RAM.
It is extremely fast (faster than any SSD), but it is erased on every power-down, so only use it for temporary files.

Of course, you should have enough RAM to spare for this disk (the memory is pre-allocated for the disk use only), but on an 8GB PC, it’s usually not an issue.

There are several programs you can use to set up a RAM disk. I used DataRam RamDisk which supplies a free version with the ability to create a RAM disk up to 4 GB (1 or 2 GB should be sufficient for any build).

Configuration of the RAM disk is very easy:

image

After you download, install and format your new RAM disk, you can move your single output folder to it. If you want to keep your output folder in the same build drive, you can simply create a symbolic link between the current output folder and a folder on the RAM disk. This way makes the using of the RAM disk optional, only for users with sufficient memory.

To create a symbolic link between your build folder and your new RAM disk folder, use the following line:

mklink /D C:\Dev\MyCurrnetBuildFolder\Source\bin R:\bin

where R: is your RAM disk folder.

Note: You should change the path according to your build folder and your RAM drive settings.

Result: Adding the RAM disk reduced compilation time to less than 5 minutes! This is a 66% reduction of the original time!

Summary

In this post, we’ve seen how you can decrease build time. Of course, I can’t make any guarantees. Every project has its own characteristics and problems, but the steps provided can probably reduce the build time if you fit the profile of standard line-of-business applications.

That’s it for now,
Arik Poznanski.

This article was originally posted at http://feeds.feedburner.com/ArikPoznanskisBlog

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Software Developer (Senior) Verint
Israel Israel
Arik Poznanski is a senior software developer at Verint. He completed two B.Sc. degrees in Mathematics & Computer Science, summa cum laude, from the Technion in Israel.

Arik has extensive knowledge and experience in many Microsoft technologies, including .NET with C#, WPF, Silverlight, WinForms, Interop, COM/ATL programming, C++ Win32 programming and reverse engineering (assembly, IL).

Comments and Discussions

 
QuestionMissing link Pin
Rahul Dhammy6-Jul-15 19:20
professionalRahul Dhammy6-Jul-15 19:20 
SuggestionLoad only projects relevant for the current task Pin
Dimitri Dering20-Aug-13 21:17
Dimitri Dering20-Aug-13 21:17 
QuestionMulti-core, Visual Studio 2012 Pin
PopeDarren17-Apr-13 12:55
PopeDarren17-Apr-13 12:55 
GeneralMy vote of 5 Pin
ShlomiO27-Jan-13 22:59
ShlomiO27-Jan-13 22:59 
Questionmsbuild and file locks Pin
JesseChisholm25-Jun-12 10:54
JesseChisholm25-Jun-12 10:54 
GeneralMy vote of 5 Pin
zenwalker198520-Jun-12 18:30
zenwalker198520-Jun-12 18:30 
QuestionThanks ! Pin
Amir Hosein Nasr2-Oct-11 10:47
Amir Hosein Nasr2-Oct-11 10:47 
I cant say any more ! Big Grin | :-D Poke tongue | ;-P
GeneralStrategy for single output folder and RAM disk Pin
Kevin Finke16-Jun-11 11:53
Kevin Finke16-Jun-11 11:53 
GeneralRe: Strategy for single output folder and RAM disk Pin
Arik Poznanski16-Jun-11 12:01
Arik Poznanski16-Jun-11 12:01 
GeneralRe: Strategy for single output folder and RAM disk Pin
Kevin Finke16-Jun-11 12:02
Kevin Finke16-Jun-11 12:02 
GeneralYou can configure all temporary files to use the ramdrive as well. Pin
cac_23-May-11 2:05
cac_23-May-11 2:05 
GeneralMy vote of 5 Pin
Rhuros17-May-11 21:05
professionalRhuros17-May-11 21:05 
GeneralMy vote of 5 Pin
AspDotNetDev17-May-11 13:56
protectorAspDotNetDev17-May-11 13:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.