Shibumi
Shibumi

Reputation: 1399

Preventing all the copy operations with msbuild and a large solution

I will immediately admit completely unfamiliarity with msbuild and hope that I'm not asking a dumb question.

We have a large .NET solution that has about 316 projects in it. During the build process, it seems like a large amount of the build time is being taken up by it copying DLLs from one folder to the next (which is, I assume, so that they're available to resolve references?). Is there a way to instruct MSBuild to just put each project's output files into one folder to avoid needing to do this? It seems like that would be a sensible thing to be able to do as ultimately we copy the final result out of the final output folder and all those other, intermediary DLLs are just wasted.

Upvotes: 5

Views: 2254

Answers (3)

SoftwareCarpenter
SoftwareCarpenter

Reputation: 3923

Building 316 projects is a lot of projects to build at once. You could look at breaking out your projects into logical solutions that separate dependencies.

Also to speed things up by setting the max CPU count property to a higher value to build your projects in parallel.

BuildInParallel is an optional boolean parameter on a MSBuild task. When BuildInParallel is set to true (its default value), multiple worker processes are generated to build as many projects at the same time as possible. For this to work correctly, the /maxcpucount switch must be set to a value greater than 1, and the system must be at least dual-core or have two or more processors.

The following is an example, taken from microsoft.common.targets, about how to set the BuildInParallel parameter. /maxcpucount:number Specifies the number of worker processes that are involved in the build. For example: C:\Windows\WinFX\v3.5>msbuild.exe *.proj /maxcpucount:3. This example instructs MSBuild to build using three MSBuild.exe processes, thus allowing three projects to build in parallel. /m is also acceptable.

Upvotes: 1

KMoraz
KMoraz

Reputation: 14164

It's possible by overriding the OutDir property. e.g.:

msbuild your.sln /p:Configuration=Release;OutDir="C:\SomeFolder\Release" /m

Additionally, you can disable the CopyLocal setting for references to speed up the build process.

Upvotes: 4

James Dingle
James Dingle

Reputation: 10911

See What are the obj and bin folders (created by Visual Studio) used for?

Be sure it is actually the copy which takes time. Run the msbuild command with /verbosity:diag (or use /flp:Filename=<myfile>;Verbosity=diag to write to a file). At the end of the file you will see the time taken by each step.

You may try to parallelize the build with the /m option. By default msbuild runs on 1 thread and with 316 projects I can imagine this can be slow.

Upvotes: 2

Related Questions