Why msbuild is so slow when nothing has changed since the last build of the solution?

后端 未结 1 1753
青春惊慌失措
青春惊慌失措 2021-02-13 05:57

I have a solution with 109 projects. A mix of all - .NET, Silverlight, MVC, Web Applications, Console applications.

Now I build it on the console using msbuild. It take

1条回答
  •  猫巷女王i
    2021-02-13 06:04

    First, take a look at that diagnostic log you're generating. Actually, first use a file logger rather than console operators to pipe console output to the log, then take a look at them logs!

    Actually, instead of /v:diag >msbuild.log, use this:

    /v:min /fl3 /flp3:warningsonly;logfile=msbuild.wrn /fl4 /flp4:errorsOnly;logfile=msbuild.err /fl5 /flp5:Verbosity=diag;logfile=msbuild.log
    

    Now your console buffer thanks you, and so do your developers for including the foresight to keep separate error-only and warning-only logs for debugging.

    Now examine that diagnostic MsBuild log, and CTRL+F for the targets that are taking a long time to run. Do you see any verbiage that denotes the target is running again even though nothing has changed? To skip a build, a target will need to have defined inputs and outputs. If the inputs (.cs) are newer than the outputs (.dll, .pdb), then it knows something must have changed and trigger a new build

    Those CompileXaml targets I believe are in the WinFx targets and do have defined inputs and outputs, can you locate the output text for one of those long-running cases and determine if an error caused it to rebuild? Does it say "Rebuilding X completely because Y could not be found"?

    Lastly, here's a fun trick to speed up your build from the command line!

    msbuild.exe /m

    This will build projects separately across multiple threads.

    0 讨论(0)
提交回复
热议问题