如何降低的MSBuild倍 [英] How to decrease MSBuild times

查看:201
本文介绍了如何降低的MSBuild倍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的情况

在C#项目我现在的工作,我们有一个相当大的解决方案(80+项目)。现在,重建5分钟时间+真正成为使用的MSBuild从VS 2008相当的问题。

In the C# project I am now working on we have a fairly big solution (80+ projects). Now rebuild times of 5 minutes+ are really becoming a quite problem using MSBuild from VS 2008.

在一分析我上周事实证明,我的生成时间花在如下:

In a analysis I did last week it turned out that my build time was spent as follows

1)将文件复制到项目,并将其重新复制到依赖于它的项目(CopyToLocal)等(60%)

1) Copying files to the projects and recopying it to the projects that depend on it (CopyToLocal) etc. (60%)

2)调用postbuild反编译/编译。 (20%)

2) Invoking a postbuild to decompile/compile. (20%)

3)做实际编译等(20%)

3) Doing the actual compilation etc (20%)

除了正常项目斌\\调试文件夹输出也复制到外部目录设置的主要装载机项目。主程序结构有点像这样

Apart from the 'normal' project bin\debug folders output is also copied to an external dir to setup the main 'loader' program. The main program structure is a bit like this

\\装载机\\ BIN \\ Loader.exe是

\loader\bin\loader.exe

\\装载机\\插件\\ plugin1 \\ plugin1.dll

\loader\plugin\plugin1\plugin1.dll

\\装载机\\插件\\ plugin1 \\ somedependency.dll

\loader\plugin\plugin1\somedependency.dll

我做什么

在企图使事情更快一点我认为以下几点:

In an attempt to make things go a little faster I thought of the following:

1复制所有文件到一个大的bin目录,并且不使用 CopyTolocal 。我不喜欢这一点,因为我们可以不再使用不同版本的相同的dll和我的bin目录越来越挺乱的。

1 Copy all the files to one a big bin directory and don't use CopyTolocal. I don't like this because we can no longer use different versions of the same dlls and my bin directory is getting quite a mess.

2 <一个href=\"http://www.hanselman.com/blog/FasterBuildsWithMSBuildUsingParallelBuildsAndMulticoreCPUs.aspx\">使用的MSBuild并行(/ M)。这在构建时间只帮助非常少的。

2 Use parallelism (/m) for MSBuild. This helps only very little in build times.

3尽量减少项目之间的依赖关系这始终是一个好东西offcourse。

3 Try to reduce dependencies between projects which is always a good thing offcourse.

4投资于硬件。我发现了一些固态研究推动但这似乎并不乐观。

4 Invest in hardware. I found some research on SolidState drives but this does not seem promising.

我的问题

我也注意到,当我做出改变,以一个项目,是在我的依赖关系树一切都得到重建的根源。即使变化为仅在私人部分和该项目的接口没有变化。

I also noticed that when I make a change to a project that is at the root of my dependency tree everything gets rebuild. Even if the change was only in the 'private' part and the interface of the project did not change.

MSBuild的使用dependend项目的时间戳,以确定是否一个项目,需要重建?

MSBuild uses a timestamp of dependend projects to determine if a project needs a rebuild??

这能变成一个不同的状态?例如,文件的校验

Can this be changed to a different condition?? For example the checksum of the file?

除了这个具体的建议,我会确保AP preciate所有建议,使建立倍的速度。

Apart from this specific suggestion i would sure appreciate all suggestions to make build times faster.

最好的问候,
马亭

Best regards, Martijn

推荐答案

我工作的500多名项目C#应用程序。项目被编译并行和copylocal设置为false。编译时间大约是没有单元测试和code覆盖率37分钟。 13分钟为增量生成,而不在code的任何变化。
如果我并行编译并设置copylocal关闭为true,编译时间> 1h40min。
我对本地构建不同的配置,门入住构建和服务器构建与部署阶段(夜间生成)。

I'm working on 500+ projects C# application. Projects are compiled in parallel and copylocal set to false. Compile time is about 37min without unit tests and code coverage. 13min for incremental build without any change in the code. If I turn off parallel compilation and set copylocal to true, compile time is > 1h40min. I have different configuration for local build, gated check-in build and server builds with deploy phase (night builds).

下面是我的经验:


  1. 复制文件输出到一个目录,如果你想建立自己的项目不平行CopyLocal设置为false是不是好主意。当多个项目引用相同的组装和MSBuild的此次尝试引用到输出文件夹的同时拷贝我的组件有时锁定。 <一href=\"http://stackoverflow.com/questions/1682096/how-do-i-override-copylocal-private-setting-for-references-in-net-from-msbuil\">This解决方案对我来说非常有帮助。我设置copylocal为false所有引用和我的build目录的大小降至10倍(10倍以下I / O)。我对本地构建和服务器构建不同的设置。不同的设置门控入住构建和全部署构建。

  2. 如果我能够并行建造,建造速度更快,更快。如果你有很强的构建服务器的/ M:2的构建应该是快2倍为/ M:1的构建。它没有任何与项目之间的依赖关系做(如果copylocal设置为false)。

  3. 您应减少项目之间的依赖关系,如果你想有快速增量构建。它有完整的构建(copylocal假)没有影响。渐进式编译时间取决于构建树改变的项目位置。

  1. Copying output files to one directory is not good idea if you want to build your projects in parallel without CopyLocal set to false. My assemblies were sometimes locked when multiple projects referenced the same assembly and MSBuild tried to copy this reference to the output folder at the same time. This solution was very helpful for me. I set copylocal to false for all references and my build dir size was lowered 10x (10 times less I/O). I have different setup for local build and for server build. Different setup for gated check-in build and for full deploy build.
  2. If I enable parallel build, builds are faster, much faster. If you have strong build server your /m:2 build should be 2x faster as /m:1 build. It has nothing to do with dependencies between projects (if copylocal is set to false).
  3. You should reduce dependencies between the projects if you want to have fast incremental build. It has no impact on full build (copylocal false). Incremental compile time depends on the changed project location in the build tree.

是的,使用的MSBuild项目dependend的时间戳,以确定是否一个项目,需要重建。它的输入文件(code文件,引用的程序集,临时文件,..)时间戳进行比较与输出装配。如果事情发生了变化,你的项目被重新编译。尽量减少项目之间depedencies的数量,以减少重新编译。如果你的变化是只有在该项目的私人的一部分,你的输出组件将被改变,装配时间戳将被更改,所有相关的项目也将被重建。你不能做很多与此有关。

Yes, MSBuild uses a timestamp of dependend projects to determine if a project needs a rebuild. It compares input files (code files, referenced assemblies, temporary files,..) timestamp with output assembly. If something is changed, your project is recompiled. Try to reduce number of depedencies between projects to minimize recompilation. If your change was only in the 'private' part of the project, your output assembly will be changed, assembly timestamp will be changed and all related projects will be rebuild also. You cannot do much with this.

而无需在code的任何变化运行构建2次诊断冗长和检查建设目标CoreCompile完全像我描述的here.你可以有一些错误在你的项目文件和项目的重新编译每次。如果你没有改变任何东西你生成日志不应该包含建设目标CoreCompile彻底的日志。

Run your build 2 times with diagnostic verbosity without any change in your code and check for "Building target "CoreCompile" completely" like I described here. You can have something wrong in your project files and your projects are recompiled every time. If you don't change anything your build log should not contain "Building target "CoreCompile" completely" logs.

我们的构建服务器是虚拟机,不是真正的硬件。它不使用虚拟机用于构建服务器不错的主意,但它不是我的决定。

Our build server is virtual machine, not real piece of hardware. It is not good idea to use VM for build server, but it was not my decision.

如果您拥有多GB RAM尝试使用它的一部分作为内存硬盘。您的构建要快很多:)

If you have multi GB RAM try to use part of it as a in-memory hard drive. Your build should be much faster :)

SSD驱动器是每天高I / O敏感。它有保修的影响。

SSD drives are sensitive to high I/O per day. It have an impact on warranty.

希望它可以帮助别人...;)

Hope it helps someone ... ;)

这篇关于如何降低的MSBuild倍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆