Is there a way to speed up the builds in visual studio team services (and TFS)

RBZ picture RBZ · Aug 4, 2015 · Viewed 8.2k times · Source

Our team has set up continuous integration using visual studio online. We have tried cranking up our subscription to advanced with a paid build limit that we are nowhere near reaching. However, build times are exceptionally slow.

The builds will sit in a queue for several minutes then take several minutes to run [even when testing adding Nuget packages to source control].

Is there any way to speed up builds in Visual Studio Online? If not what are some good alternatives?

I see acceptance or setting up our own continuous integration server on an Azure VM as a worst case fallback.

Answer

jessehouwing picture jessehouwing · Jul 2, 2016

The Hosted build servers suffer a few flaws. First, they're always clean images with nothing preserved, so your sources, packages and previously built binaries are not available. Because of this, the only way to further speed up the build is to:

  • Reduce the number of projects you build by re-using previous results in the form of NuGet packages. This would require you to break the solution into smaller bits and use the Package Management features of Visual Studio Team Services, or of a 3rd party service like MyGet.
  • Parallelize your builds. If you're building multiple projects or multiple configurations make use of the ability to MultiConfiguration option to spin up multiple builds on multiple agents (you do need to allocate multiple hosted agents in this case) enter image description here
  • Enable BuildInParallel to allow MsBuild to spin up multiple instances and enable MaxCpuCount=2 to use multiple CPU cores available on the hosted agents. It looks like they run on an A3 instance, which gives you 4 cores to play with. If you're using both BuildInParallel and MaxCpuCount don't max out the number of cores on MaxCpuCount.
  • Build all output to a single directory using OutputPath.
  • Enable parallel test execution using the checkbox on the build task.
  • Tweak your workspace mappings as much as you can. Cloak folders that are not needed, map only what you really need.
  • Skip everything you don't really need for your CI build. You may want to turn off Code Analaysis and run your full test suite only on a nightly build to increase your feedback time, even though you're reducing your feedback quality.

This is about as much as you can do. You can't rent faster VM's in the hosted pool and you can't use any of the features in MsBuild which would allow you to do incremental builds or at least incremental updates of the workspace. and there is no way to remove the initialization time of the agent and the source retrieval.

To really speed up, you'll need to setup your own build server. Using a DS Azure VM running on a permanent SSD will give you the most performance benefit. With your own VM you can do the following additional things:

  • Turn off Clean Workspace. This will allow incremental source control fetches.
  • Turn off Clean Build. This will allow MsBuild to perform incremental builds.
  • Install multiple agents on the same machine with enough CPU's build multiple configurations on parallel on the same VM.
  • Install a TFVC Proxy (use the TFS 2013 version) on the build agent for locally stored files in case you want to build with a clean workspace, but get advantage of faster source retrieval for TFVC.
  • In case you're using Pre/Postbuild events, ensure that they specify their Inputs and Outputs so that MsBuild deduce whether the target can be skipped for incremental builds.

Instead of hosting the agent on Azure, you can install a local build agent on a beefy developer workstation or an existing local server as well.

There are other MsBuild tips and tricks you could apply to further iprove performance of MsBuild. It may amaze you how much time you can shave off your builds that way.