重建和清理之间的区别+ 在 Visual Studio 中构建

发布于 2024-08-02 03:28:28 字数 159 浏览 6 评论 0原文

在 Visual Studio 2008 中仅进行重建与进行清理 + 构建有什么区别? Clean + BuildClean + Rebuild 不同吗?

What is the difference between just a Rebuild and doing a Clean + Build in Visual Studio 2008? Is Clean + Build different then doing Clean + Rebuild?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

失退 2024-08-09 03:28:28

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

值得注意的细节:

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

  2. 所有三个操作都对应于 MSBuild 目标。 因此,项目可以覆盖“重建”操作来执行完全不同的操作。

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.

凌乱心跳 2024-08-09 03:28:28

Earl 是正确的,99% 的情况下重建 = 清理 + 构建。

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

这是一个极端的案例,但由于评论讨论而指出。

Earl is correct that 99% of the time 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).

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

来世叙缘 2024-08-09 03:28:28

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

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

  2. 每个解决方案:重建 sln = sln 中的 foreach 项目(清理项目 + 构建项目)。

请注意,由于执行顺序的差异,Rebuild sln 与 (Clean sln + Build sln) = (foreach 项目在 sln Clean 项目中) + (foreach 项目在 sln Build 项目中) 并不相同。 此外,这个“foreach”可以并发执行,因此允许不同的任务在两种情况下同时运行。

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

  • 重建 sln = (清理 proj1 + 构建 proj1) & (清理 proj2 + 构建 proj2)& (清理 proj3 + 构建 proj3)

  • 清理 Sln + 构建 Sln = (清理 proj1 & 清理 proj2 & 清理 proj3) + (构建 proj1 & 构建 proj2 & 构建 proj3)

+ 表示串行,& 意思是并发。

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

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

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

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

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.

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

  • 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)

+ 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.

残花月 2024-08-09 03:28:28

来自 http://www.cs.tufts.edu/r/ Graphics/resources/vs_getting_started/vs_getting_started.htm,(刚刚google了一下):

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

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

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

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

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. 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 .

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.

多孤肩上扛 2024-08-09 03:28:28

来自这篇博文 作者链接为对此问题的评论

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

区别在于项目清理和构建的顺序。 让
假设我们的解决方案中有两个项目。 清理然后构建
对两个项目执行 clean,然后分别进行构建
在重建项目 A 时,将进行清理,然后再构建
项目 B 将被清理,然后构建,依此类推。

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.

舞袖。长 2024-08-09 03:28:28

Visual Studio 2022 文档说明:

  • 选择 BuildBuild Solution,或按 Ctrl+Shift+B,仅编译自最近以来已更改的项目文件和组件建造。 当解决方案包含多个项目时,“生成”命令将变为“生成解决方案”。
  • 选择重建解决方案来“清理”解决方案,然后构建所有项目文件和组件。
  • 选择Clean Solution删除所有中间文件和输出文件。 只剩下项目和组件文件,然后就可以构建中间文件和输出文件的新实例。

build-配置管理器菜单

此信息以及更多信息,请参见:https://learn.microsoft.com/en-us/visualstudio/ide/building-and-cleaning-projects-and -solutions-in-visual-studio?view=vs-2022

Documentation for Visual Studio 2022 explains:

  • Choose Build or Build Solution, or press Ctrl+Shift+B, to compile only those project files and components that have changed since the most recent build. The Build command becomes Build Solution when a solution includes more than one project.
  • Choose Rebuild Solution to "clean" the solution and then build all project files and components.
  • Choose Clean Solution to delete any intermediate and output files. With only the project and component files left, new instances of the intermediate and output files can then be built.

build-configuration-manager-menu

This, and more information, here: https://learn.microsoft.com/en-us/visualstudio/ide/building-and-cleaning-projects-and-solutions-in-visual-studio?view=vs-2022

萌无敌 2024-08-09 03:28:28

另一个区别:Clean 会清除 Test Explorer 中的测试结果,而 Rebuild 则不会。

Another difference: Clean clears the test results in Test Explorer, which Rebuild doesn't.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文