visual-studio Visual Studio 中生成解决方案、重建解决方案和清理解决方案之间的区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3095901/
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
Difference between Build Solution, Rebuild Solution, and Clean Solution in Visual Studio?
提问by Fawa
What is the difference between Build Solution, Rebuild Solution, and Clean Solution in Visual Studio?
Visual Studio 中的 Build Solution、Rebuild Solution 和 Clean Solution 有什么区别?
When is the appropriate time to use each one of these?
什么时候是使用其中每一种的合适时间?
回答by Jon Skeet
- Build solutionwill perform an incremental build: if it doesn't thinkit needs to rebuild a project, it won't. It may also use partially-built bits of the project if they haven't changed (I don't know how far it takes this)
- Rebuild solutionwill clean and then build the solution from scratch, ignoring anything it's done before. The difference between this and "Clean, followed by Build" is that Rebuild will clean-then-build each project, one at a time, rather than cleaning all and then building all.
- Clean solutionwill remove the build artifacts from the previous build. If there are any other files in the build target directories (bin and obj) they may not be removed, but actual build artifacts are. I've seen behaviour for this vary - sometimes deleting fairly thoroughly and sometimes not - but I'll give VS the benefit of the doubt for the moment :)
- 构建解决方案将执行增量构建:如果它认为不需要重建项目,则不会。如果它们没有改变,它也可能使用项目的部分构建部分(我不知道这需要多远)
- 重建解决方案将清理并从头开始构建解决方案,忽略之前完成的任何事情。这与“清理,然后构建”之间的区别在于,重建将清理然后构建每个项目,一次一个,而不是先清理所有项目,然后再构建所有项目。
- 干净的解决方案将从以前的构建中删除构建工件。如果构建目标目录(bin 和 obj)中有任何其他文件,它们可能不会被删除,但实际的构建工件是。我已经看到这种情况的行为有所不同 - 有时删除得相当彻底,有时没有 - 但我暂时会给 VS 带来怀疑的好处:)
(The links are to the devenv.execommand line switches, but they do the same as the menu items.)
(链接指向devenv.exe命令行开关,但它们的作用与菜单项相同。)
回答by Shivprasad Ktheitroadala
Build solution: Compiles code files (DLL and EXE) which are changed.
构建解决方案:编译已更改的代码文件(DLL 和 EXE)。
Rebuild: Deletes all compiled files and compiles them again irrespective if the code has changed or not.
重建:删除所有已编译的文件并重新编译,无论代码是否更改。
Clean solution: Deletes all compiled files (DLL and EXE file).
干净的解决方案:删除所有已编译的文件(DLL 和 EXE 文件)。
You can see this YouTube video (Visual Studio Build vs. Rebuild vs. Clean (C# interview questions with answers)) where I have demonstrated the differences and below are visual representations which will help you to analyze the same in more detail.
您可以观看此 YouTube 视频(Visual Studio Build vs. Rebuild vs. Clean(C# 面试问题及答案)),其中我展示了不同之处,下面是可视化表示,可帮助您更详细地分析相同之处。


The difference between Rebuild vs. (Clean + Build), because there seems to be some confusion around this as well:
Rebuild 与 (Clean + Build) 之间的区别,因为在这方面似乎也存在一些混淆:
The difference is the way the build and clean sequence happens for every project. Let's say your solution has two projects, “proj1” and “proj2”. If you do a rebuild it will take “proj1”, clean (delete) the compiled files for “proj1” and build it. After that it will take the second project “proj2”, clean compiled files for “proj2” and compile “proj2”.
不同之处在于每个项目的构建和清理序列发生的方式。假设您的解决方案有两个项目,“proj1”和“proj2”。如果您进行重建,它将使用“proj1”,清理(删除)“proj1”的编译文件并构建它。之后,它将使用第二个项目“proj2”,清理“proj2”的编译文件并编译“proj2”。
But if you do a “clean” and build”, it will first delete all compiled files for “proj1” and “proj2” and then it will build “proj1” first followed by “proj2”.
但是如果你进行“clean”和“build”,它会首先删除“proj1”和“proj2”的所有编译文件,然后它会先构建“proj1”,然后是“proj2”。


回答by Matthew Jones
Taken from this link:
取自此链接:
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 意味着编译和链接所有源文件,无论它们是否发生变化。构建是正常的事情,而且速度更快。有时,项目目标组件的版本可能会不同步,因此需要重新构建才能使构建成功。在实践中,您永远不需要清洁。
回答by Justin Niessner
Build Solution- Builds any assemblies which have changed files. If an assembly has no changes, it won't be re-built. Also will not delete any intermediate files.
构建解决方案- 构建任何已更改文件的程序集。如果程序集没有更改,则不会重新构建。也不会删除任何中间文件。
Used most commonly.
最常用。
Rebuild Solution- Rebuilds all assemblies regardless of changes but leaves intermediate files.
重建解决方案- 重建所有程序集而不考虑更改,但保留中间文件。
Used when you notice that Visual Studio didn't incorporate your changes in the latest assembly. Sometimes Visual Studio does make mistakes.
当您注意到 Visual Studio 未将您的更改合并到最新程序集中时使用。有时 Visual Studio 确实会出错。
Clean Solution- Delete all intermediate files.
清理解决方案- 删除所有中间文件。
Used when all else fails and you need to clean everything up and start fresh.
当所有其他方法都失败并且您需要清理所有内容并重新开始时使用。
回答by Ken Richards
I just think of Rebuild as performing the Clean first followed by the Build. Perhaps I am wrong ... comments?
我只是认为重建是先执行清理,然后再执行构建。也许我错了...评论?
回答by Guilherme Fidelis
Build Solution– Builds any assemblies which have changed files. If an assembly has no changes, it won't be re-built. Also will not delete any intermediate files.
构建解决方案——构建任何已更改文件的程序集。如果程序集没有更改,则不会重新构建。也不会删除任何中间文件。
Rebuild solutionwill clean and then build the solution from scratch, ignoring anything it's done before
重建解决方案将清理并从头开始构建解决方案,忽略之前所做的任何事情
Clean Solutionwill delete all compiled files (i.e., EXE's and DLL's) from the bin/obj directory.
Clean Solution将从bin/obj 目录中删除所有已编译的文件(即EXE 和DLL)。
回答by Steven Evers
Build solution will build any projects in the solution that have changed. Rebuild builds all projects no matter what, clean solution removes all temporary files ensuring that the next build is complete.
构建解决方案将构建解决方案中已更改的任何项目。无论如何,重建都会构建所有项目,干净的解决方案会删除所有临时文件,确保下一次构建完成。
回答by Sabaridass R
Build Solution- Build solution will build your application with building the number of projects which are having any file change. And it does not clear any existing binary files and just replacing updated assemblies in bin or obj folder.
构建解决方案- 构建解决方案将通过构建具有任何文件更改的项目数量来构建您的应用程序。它不会清除任何现有的二进制文件,只是替换 bin 或 obj 文件夹中的更新程序集。
Rebuild Solution- Rebuild solution will build your entire application with building all the projects are available in your solution with cleaning them. Before building it clears all the binary files from bin and obj folder.
重建解决方案- 重建解决方案将构建您的整个应用程序,构建解决方案中可用的所有项目并对其进行清理。在构建之前,它会清除 bin 和 obj 文件夹中的所有二进制文件。
Clean Solution- Clean solution is just clears all the binary files from bin and obj folder.
清洁解决方案- 清洁解决方案只是清除 bin 和 obj 文件夹中的所有二进制文件。
回答by Sajisha
Build solution
构建解决方案
This will perform an incremental build. In other words it will only build code files which have changed. If they have not changed those files will not be touched.
这将执行增量构建。换句话说,它只会构建已更改的代码文件。如果他们没有改变那些文件将不会被触及。
Rebuild solution
重建方案
This will delete all currently compiled files (i.e., exe and DLLs) and will build everything from scratch, irrespective of if there is code change in the file or not.
这将删除所有当前已编译的文件(即 exe 和 DLL)并将从头开始构建所有内容,无论文件中是否有代码更改。
Clean solution menu
清洁解决方案菜单
This menu will delete all compiled files (i.e., EXE's and DLL's) from the bin/obj directory.
该菜单将从 bin/obj 目录中删除所有已编译的文件(即 EXE 和 DLL)。
Rebuild = Clean + Build
重建 = 清理 + 构建
回答by Chase
The one major thing I think people are leaving out is that Build and Clean are both tasks that are performed based on Visual Studio's knowledge of your Project/Solution. I see a lot of complaining that Clean doesn't work or leaves leftover files or is not trustworthy, when in fact, the reasons you say it isn't trustworthy actually makes it more trustworthy.
我认为人们遗漏的一件主要事情是 Build 和 Clean 都是基于 Visual Studio 对您的项目/解决方案的知识执行的任务。我看到很多抱怨 Clean 不起作用或留下剩余文件或不值得信赖,而实际上,您说它不值得信赖的原因实际上使它更值得信赖。
Clean will only remove (clean) files and/or directories that Visual Studio or the compiler themselves have in fact created. If you copy your own files or files/folder structures get created from an outside tool or source, then Visual Studio doesn't "know they exist" and therefore, should not touch them.
Clean 只会删除(清理)Visual Studio 或编译器本身实际上创建的文件和/或目录。如果您复制自己的文件或从外部工具或源创建的文件/文件夹结构,则 Visual Studio 不会“知道它们存在”,因此不应接触它们。
Can you imagine if the Clean operation basically performed a "del *.*" ? This could be catastrophic.
您能想象 Clean 操作是否基本上执行了“del *.*”?这可能是灾难性的。
Buildperforms a compile on changed or necessary projects.
Build对更改的或必要的项目执行编译。
Rebuildperforms a compile regardless of change or what's necessary.
Rebuild执行编译而不管更改或什么是必要的。
Cleanremoves files/folders it has created in the past, but leaves anything that it didn't have anything to do with, initially.
Clean会删除它过去创建的文件/文件夹,但会保留最初与它无关的任何内容。
I hope this elaborates a bit and helps.
我希望这能详细说明并有所帮助。

