Visual Studio中Rebuild和Clean + Build之间的区别

本文翻译自:Difference between Rebuild and Clean + Build in Visual Studio

What is the difference between just a Rebuild and doing a Clean + Build in Visual Studio 2008? 只是重建和在Visual Studio 2008中执行Clean + Build之间有什么区别? Is Clean + Build different then doing Clean + Rebuild ? Clean + Build是不同的,然后做Clean + Rebuild


#1楼

参考:https://stackoom.com/question/5ewh/Visual-Studio中Rebuild和Clean-Build之间的区别


#2楼

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. 所有这三个操作都对应于MSBuild目标。 So a project can override the Rebuild action to do something completely different. 因此,项目可以覆盖重建操作以执行完全不同的操作。


#3楼

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. 3个动作(重建,构建,清理)代表不同的MSBuild目标。 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). 因此,在启动clean + build(或完全删除它们)之前,某人完全有可能覆盖rebuild以执行多个操作。

Very much a corner case but pointing it out due to comment discussions. 非常一个极端的案例,但由于评论讨论指出它。


#4楼

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 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. 构建或重建解决方案构建或重建解决方案中的所有项目,而构建或重建构建或重建StartUp项目,在上面的屏幕截图中“hello”。 To set the StartUp project, right click on the desired project name in the Solution Explorer tab and select Set as StartUp project. 要设置StartUp项目,请在Solution Explorer选项卡中右键单击所需的项目名称,然后选择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 . 由于家庭作业解决方案通常只有一个项目,因此构建或重建解决方案实际上与构建或重建相同。

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. Ctrl-F7是Compile的快捷键。


#5楼

From this blog post which 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之后构建B将是干净的,然后构建等等。


#6楼

1 Per project, Rebuild project = (Clean project + Build project). 1每个项目,重建项目=(清理项目+构建项目)。

2 Per Solution, Rebuild Sln = foreach project (Clean project + Build project) != Clean Sln + Build Sln 2每个解决方案,重建Sln = foreach项目(清理项目+构建项目)!= Clean Sln + Build Sln

Say you have a Sln, contains proj1, proj2, and proj3. 假设您有一个Sln,包含proj1,proj2和proj3。

Rebuild Sln = (Clean proj1 -> Build Proj1) + (Clean proj2 -> Build Proj2) + (Clean proj3 -> 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) Clean Sln + Build Sln =(清洁proj1 + Clean proj2 + Clean proj3) - >(构建proj1 + Build proj2 + Build proj3)

-> means serial, + means concurrent - >表示串行,+表示并发

so there is a chance when you submit a lot of code changes while you don't configured the project dependencies correctly, Rebuild Sln would cause some of you proj link to a stale lib because all builds aren't guaranteed being after all cleans.(In this case, Clean Sln + Build Sln will give a link error, and let you know that immediately, instead of giving you an app with odd behavior) 因此,当您没有正确配置项目依赖项时,有可能提交大量代码更改,Rebuild Sln会导致您的某些项目链接到陈旧的lib,因为所有构建都不能保证在完全清除之后。(在这种情况下,Clean Sln + Build Sln会给出链接错误,并立即通知您,而不是给您一个奇怪行为的应用程序)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值