visual-studio 如果您的 Build 在 Visual Studio 中花费的时间太长,最佳实践
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/431249/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Best practices if your Build is taking too long in Visual Studio
提问by Manish
I have moderate size solution in Visual Studio which takes around 5 minutes to build (It take that long because of FxCop and other post build steps). My problem is, Visual Studio stops responding while it's building. You can't continue working as VS almost hangs. I tried using two VS instances, just using one for build, but it keeps crashing every now and then.
我在 Visual Studio 中有中等大小的解决方案,它需要大约 5 分钟的时间来构建(由于 FxCop 和其他后期构建步骤,需要这么长时间)。我的问题是,Visual Studio 在构建时停止响应。您无法继续工作,因为 VS 几乎挂起。我尝试使用两个 VS 实例,只使用一个进行构建,但它时不时地崩溃。
My question is, How to not waste time looking at Visual Studio building your large/moderate project. Are there any best practices for this?
我的问题是,如何不浪费时间查看 Visual Studio 构建大型/中等项目。是否有任何最佳做法?
回答by DavGarcia
Two excellent MSBuild tips I just learned yesterday...
我昨天刚学到的两个优秀的 MSBuild 技巧......
You can run tasks in parallel by using the /m:n switch where n is the number of processors to use. All you have to do is set BuildInParallelon your MSBuild task.
您可以使用 /m:n 开关并行运行任务,其中 n 是要使用的处理器数。您所要做的就是在您的 MSBuild 任务上设置BuildInParallel。
The other trick is that if you have several <exec /> tasks to run you can actually run them in parallel too by calling <exec command="sleep 10|sleep 10|sleep 20" /> by using the pipe character between each command. A more practical example:
另一个技巧是,如果您有多个 <exec /> 任务要运行,您实际上也可以通过在每个命令之间使用管道字符调用 <exec command="sleep 10|sleep 10|sleep 20" /> 来并行运行它们. 一个更实际的例子:
<CreateItem Include="server1;server2;server3;server2">
  <Output ItemName="IISServer" TaskParameter="Include"/>
</CreateItem>
<CreateProperty Value="@(IISServer->'iisreset.exe /start %(Identity)', '|')">
  <Output TaskParameter="Value" PropertyName="IISServerStartAll" />
</CreateProperty>
<exec command="$(IISServerStartAll)" />
回答by Romain Verdier
- You certainly don't need to run a static code analysis each time you build your solution.
- Reduce the number of your project by merging some could also helps a lot.
- 您当然不需要每次构建解决方案时都运行静态代码分析。
- 通过合并一些项目来减少项目数量也有很大帮助。
What other post build tasks have you put in place ?
您还实施了哪些其他后期构建任务?
回答by ufukgun
Use Incredibuild if you have more than one computer or setup this program to another friends at work. it is easy to setup and use. speed up is linear for compiling.
如果您有不止一台计算机,请使用 Incredibuild,或者为工作中的其他朋友设置此程序。它易于设置和使用。加速对于编译是线性的。
it is also good for multicore cpu's bacause normally vs uses one core for one project but incredibuild make it parallel for each .cpp file...
它也有利于多核 cpu 的 bacause 通常对一个项目使用一个核心但 incredibuild 使它对每个 .cpp 文件并行...
try and see.. :)
试试看.. :)
回答by Charlie Salts
You might consider a dedicated build machine using MSBuild. From there, you'd be able to continue working while compiling. It does make it more complicated, though, as you're introducing networking issues.
您可以考虑使用 MSBuild 的专用构建机器。从那里,您将能够在编译时继续工作。但是,当您引入网络问题时,它确实使它变得更加复杂。
回答by user35978
You can create classes in another project by stubbing the classes that you would need to make the code compiles. This way, you can test and document your new code. After this, you just include it to the real project and you compile "for real". By the time it compiles, you are already working on another snippet of the project because you are 95% it will successfully compiles. Or, by the time it compiles, you can also write your unit tests..
您可以通过存根使代码编译所需的类在另一个项目中创建类。这样,您就可以测试和记录新代码。在此之后,您只需将其包含到实际项目中,然后“真正地”编译即可。到它编译时,您已经在处理该项目的另一个片段,因为您 95% 它将成功编译。或者,在编译时,您还可以编写单元测试。


