“Build Solution” and “Rebuild Solution” are the most commonly used features in Visual Studio. As a developer you writes code, build the solution and run the application in Visual Studio. Very often you also used “rebuild solution” , or “clean and then build solution”. Have you ever wonder why there are different options ? When to use them? Though many of you are familiar with the details of these but when asked, I have seen many beginners having confusion around it.
So let’s try to simply it by asking below questions
- What is the difference between Build and Rebuild ?
- When to use which option ?
- How does clean relates , when to use it ?
One-liner Understanding…
- Build Solution – Incremental build and compiles only the files that are changed.
- Clean Solution – Deletes all compiled, intermediate files.
- Rebuild Solution – Deletes all compiled files and compiles all irrespective of changes.
Now take a deeper look ….
Build Solution
This is the faster option to compile and run your solution in Visual Studio. When you opt for the Build, Visual Studio will perform an incremental build. What does it mean ?
- Builds any assemblies which have changed files from the last build. If there an assembly which has no changes, it won’t be re-built.
- During the Build option, Visual Studio won’t delete any intermediate files.
So, for a single solution, if you build it for first time, and verify the detailed log at output window, you should be able to see information as similar to shown in below..
If here is no changes, and try to build it again, it will display message like below – which says .. all the code base are up-to-date
Incase there are multiple projects, all up-to-date projects will be skipped and only the changed files will be built.
Clean Solution
This will remove all intermediary, complied files and clean up the output directories (bin / obj folders) from any previous builds.
Detailed wiew of Output Windows will display very similar information like shown in below screenshot…
When execute, Clean Solutions, Cleans the project one by one.
Now if you execute build after the clean, you will have following steps of execution ( Post Clean Solution)
Rebuild Solution
As mentioned earlier, rebuild a solution is nothing but clean and build each project in the solution.
Rebuilding a solution first does the “Clean Solution” then execute the “Build Solution” for each project.
Note: This sequence of project execution from the list of project will depends on the project dependency. For an instance, project build sequence for below two different dependency diagram would be different.
Well, just to summarize let me write done the same one-liners once again
Build Solution – Incremental Build and Compiles only the files that are changed.
Clean Solution – Deletes all compiled, intermediate files
Rebuild Solution – Deletes all compiled files and Compiles them all irrespective of changes
Hope it was helpful …
Pingback: How to identify the project dependencies in Visual Studio ?
Pingback: Back to Basic : Displaying detailed output of MSBuild in Visual Studio output Window
Pingback: Color Indicator for Code Changes and Visual Studio IDE Status Change