visual-studio Visual Studio 中重建和清理 + 构建的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1247457/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:50:48  来源:igfitidea点击:

Difference between Rebuild and Clean + Build in Visual Studio

visual-studiovisual-studio-2008buildrebuild

提问by Jim McKeeth

What is the difference between just a Rebuildand doing a Clean+ Buildin Visual Studio 2008? Is Clean+ Builddifferent then doing Clean+ Rebuild?

在 Visual Studio 2008 中仅重建和执行Clean+ Build有什么区别?是清洁+构建不同然后做清洁+重建

回答by earl

Rebuild = Clean + Build (usually)

重建 = 清理 + 构建(通常)

Notable details:

值得注意的细节:

  1. For a multi-project solution, "rebuild solution" does a "clean" followed by a "build" for each project (possibly in parallel). Whereas a "clean solution" followed by a "build solution" first cleans all projects (possibly in parallel) and then builds all projects (possibly in parallel). This difference in sequencing of events can become significant when inter-project dependencies come into play.

  2. All three actions correspond to MSBuild targets. So a project can override the Rebuild action to do something completely different.

  1. 对于多项目解决方案,“重建解决方案”对每个项目进行“清理”,然后进行“构建”(可能并行)。而“干净的解决方案”后跟“构建解决方案”首先清理所有项目(可能并行),然后构建所有项目(可能并行)。当项目间的依赖发挥作用时,事件顺序的这种差异会变得很明显。

  2. 所有三个操作都对应于 MSBuild 目标。因此,一个项目可以覆盖 Rebuild 操作来做一些完全不同的事情。

回答by JaredPar

Earl is correct that 99% of the time Rebuild = Clean + Build.

Earl 是正确的,99% 的时间 Rebuild = Clean + Build。

But they are not guaranteed to be the same. The 3 actions (rebuild, build, clean) represent different MSBuild targets. Each of which can be overriden by any project file to do custom actions. So it is entirely possible for someone to override rebuild to do several actions before initiating a clean + build (or to remove them entirely).

但不能保证它们是相同的。3 个操作(重建、构建、清理)代表不同的 MSBuild 目标。每一个都可以被任何项目文件覆盖以执行自定义操作。因此,有人完全有可能在启动清理 + 构建(或完全删除它们)之前覆盖重建以执行多个操作。

Very much a corner case but pointing it out due to comment discussions.

非常极端的情况,但由于评论讨论而指出。

回答by Trout.Z

Let's define default Rebuild implementation in terms of default Clean and Build implementations:

让我们根据默认的 Clean 和 Build 实现来定义默认的 Rebuild 实现:

  1. Per project: Rebuild project = Clean project + Build project.

  2. Per solution: Rebuild sln = foreach project in sln (Clean project + Build project).

  1. 每个项目:重建项目 = 清理项目 + 构建项目。

  2. 每个解决方案:在 sln 中重建 sln = foreach 项目(Clean 项目 + Build 项目)。

Note that due to differences in the order of execution, Rebuild sln is not the same as (Clean sln + Build sln) = (foreach project in sln Clean project) + (foreach project in sln Build project). Also, this "foreach" may execute concurrently, so different tasks are allowed to run concurrently in the two scenarios.

注意由于执行顺序的不同,Rebuild sln和(Clean sln + Build sln) = (sln Clean project中的foreach project) + (sln Build project中的foreach project)是不一样的。此外,这个“foreach”可能会并发执行,因此在两种场景中允许不同的任务并发运行。

Say you have a sln that contains proj1, proj2, and proj3.

假设您有一个包含 proj1、proj2 和 proj3 的 sln。

  • Rebuild sln = (Clean proj1 + Build proj1) & (Clean proj2 + Build proj2) & (Clean proj3 + Build proj3)

  • Clean Sln + Build Sln = (Clean proj1 & Clean proj2 & Clean proj3) + (Build proj1 & Build proj2 & Build proj3)

  • 重建 sln = (Clean proj1 + Build proj1) & (Clean proj2 + Build proj2) & (Clean proj3 + Build proj3)

  • Clean Sln + Build Sln = (Clean proj1 & Clean proj2 & Clean proj3) + (Build proj1 & Build proj2 & Build proj3)

+ means serial, & means concurrent.

+ 表示串行,& 表示并发。

So if project dependencies are not configured correctly, there is a chance that when you execute Rebuild sln, some of your projects link to a stale lib. That's because all cleans are not guaranteed to be finished before the first build starts. If you execute Clean sln + Build sln, they will give a link error and let you know that immediately, instead of giving you an app with odd behavior.

因此,如果未正确配置项目依赖项,则当您执行 Rebuild sln 时,您的某些项目可能会链接到过时的库。这是因为不能保证在第一次构建开始之前完成所有清理。如果您执行 Clean sln + Build sln,它们会给出链接错误并立即通知您,而不是为您提供具有奇怪行为的应用程序。

回答by Eduardo Mello

From http://www.cs.tufts.edu/r/graphics/resources/vs_getting_started/vs_getting_started.htm, (just googled it):

http://www.cs.tufts.edu/r/graphics/resources/vs_getting_started/vs_getting_started.htm,(只是用谷歌搜索):

Build means compile and link only the source files that have changed since the last build, while Rebuild means compile and link all source files regardless of whether they changed or not. Build is the normal thing to do and is faster. Sometimes the versions of project target components can get out of sync and rebuild is necessary to make the build successful. In practice, you never need to Clean.

Build 意味着只编译和链接自上次构建以来发生变化的源文件,而 Rebuild 意味着编译和链接所有源文件,无论它们是否发生变化。构建是正常的事情,而且速度更快。有时,项目目标组件的版本可能会不同步,因此需要重新构建才能使构建成功。在实践中,您永远不需要清洁。

Build or Rebuild Solution builds or rebuilds all projects in the your solution, while Build or Rebuild builds or rebuilds the StartUp project, "hello" in the screen shot above. To set the StartUp project, right click on the desired project name in the Solution Explorer tab and select Set as StartUp project. The project name now appears in bold. Since the homework solutions typically have only one project, Build or Rebuild Solution is effectively the same as Build or Rebuild .

Build or Rebuild Solution 构建或重建解决方案中的所有项目,而 Build 或 Rebuild 构建或重建 StartUp 项目,在上面的屏幕截图中显示“hello”。要设置启动项目,请在解决方案资源管理器选项卡中右键单击所需的项目名称,然后选择设置为启动项目。项目名称现在以粗体显示。由于作业解决方案通常只有一个项目,因此 Build or Rebuild Solution 实际上与 Build or Rebuild 相同。

Compile just compiles the source file currently being edited. Useful to quickly check for errors when the rest of your source files are in an incomplete state that would prevent a successful build of the entire project. Ctrl-F7 is the shortcut key for Compile.

Compile 只是编译当前正在编辑的源文件。当其余源文件处于不完整状态时快速检查错误很有用,这会阻止整个项目的成功构建。Ctrl-F7 是编译的快捷键。

回答by Prageeth godage

From this blog postwhich the author linked as a comment on this question:

从作者链接的这篇博客文章中作为对这个问题的评论

Actually No!!! they are not equal.

The difference is in the sequence projects get clean and build. Let say we have two projects in a solution. Clean and then build will perform clean to both projects and then build will occur individually while on rebuild project A will get and clean and then build after that project B will be clean and then build and so on.

其实没有!!!他们并不平等。

不同之处在于项目得到清理和构建的顺序。假设我们在一个解决方案中有两个项目。清理然后构建将对两个项目执行清理,然后构建将单独发生,而在重建项目 A 将获取并清理,然后在该项目 B 清理后构建,然后构建等等。