Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reasons for C# projects to rebuild in Visual Studio

I have a large solution, of some 320 projects, where even small changes to a single web form result in long build times to test/debug a small change. I suspect post-build file copy tasks for 'touching' file datetimes and causing multiple rebuilds.

Are there any other reasons for VS 2010 to run a rebuild other than source files being newer than binary output files, in the absence of any strong naming and versioning influences?

ADDENDUM: I have no immediate influence on the size or shape of the source tree. It is the trunk of a stable core product and any short-term "non-business" changes are considered risky and or costly. I will raise points mentioned in answers I receive here as input to future directions of the project.

like image 366
ProfK Avatar asked Mar 25 '11 07:03

ProfK


People also ask

How many caesareans can a woman have?

“So, every patient is different and every case is unique. However, from the current medical evidence, most medical authorities do state that if multiple C-sections are planned, the expert recommendation is to adhere to the maximum number of three.”

Is C-section safer?

Which is safer: vaginal birth or C-section? Vaginal birth is much safer than a C-section for most women and babies. Sometimes a C-section is the only safe option, like when the baby is positioned side-to-side in the belly (transverse lie) or the placenta is covering the cervix (placenta previa).


2 Answers

C# rebuilds because a file has been changed, or a dependency has been changed, but also frequently for "no obvious reason". You can often build 2 or 3 times in a row without making a single change and C# will trundle off and rebuild vast amounts of the code.

Turn on Tools > Options > Projects and Solutions > Build and Run > Only build startup projects and dependencies on run. This will minimise the build to only the dependencies of the project you intend to execute, so unless everything is one massive dependency tree, this will significantly reduce the number of projects considered in the build.

The better solution, however, is to avoid asking it to compile in the first place.

  • Every project adds an additional overhead to the build. On my PC this is around 3 seconds. By merging the code of two projects into one .csproj files I save 3 seconds of build time. So for 300+ projects you could knock 10 minutes off the build time just by merging projects - i.e. where possible use many modules/namespaces in one assembly rather than many assemblies. You'll find your application startup time is improved too.

  • Many projects don't need building all the time. Break these out as library projects and just link to (reference) the binaries

  • Also disable "copy local" and instead point all OutputPaths to a shared folder - this will significantly reduce the overheads by avoiding making 320 copies of 320 dlls all over your hard drive.

  • Add new build configurations (e.g. "Debug FastBuild") that only build the assemblies you are actually working on. With the configguration manager you can untick projects you don't want to build, and presto, they are ignored by the build system. After you get code from source control, build a full "Debug" build to refresh everything, and then switch back to "fastbuild"

like image 143
Jason Williams Avatar answered Oct 02 '22 22:10

Jason Williams


You can try to build your solution using msbuild and /v:d (for diagnostics logging).

There may be hints in the log for why a project is not up to date.

like image 33
Arve Avatar answered Oct 02 '22 22:10

Arve