There isn’t any .NET developer using Visual Studio as IDE hasn’t used Clean, Build and Rebuild features as part of the Solution Explorer. They come in handy when we work on large projects having multiple references, projects which get updated very often or are hardly updated with any code changes.
Recently, I have being dealing with solutions having more than 40 projects with lots of proxy service references. The source code in TFS gets checked almost every hour. Sometimes it says “BUILD SUCCEED” but on running the application, everything breaks down.
I just CLEAN Solution, then REBUILD or BUILD Solution, it starts working. This isn’t magic in Visual Studio nor is it best practice to follow but it's worth knowing that what actually Clean, Build & Rebuild in Visual Studio main functionality is.
Creating a Solution in Visual Studio with Different Projects
When we check the folders in this solution, it contains only files which we created in the above steps along with project files. Then, build solution in 2 ways “Right click solution –> Build Solution” or Press F6 key.
If we see now in file explorer, few folders got created like “bin”, “Debug”, “Release”, “obj”, this is the effect of BUILD SOLUTION telling that “I have now transformed the C# code into assembly”.
Referring Another Library in a Project
In the project “
EmployeeDetails.UI“, add “
EmployeeDetails” class library project. Now either BUILD or REBUILD solution. Here in this step “
EmployeeDetails.UI” will be added with assembly and any other files part of class library. The below screen shot shows DLL, EXE, XML files of both projects.
Figure 2: Assemblies, Files, Configs when we build or rebuild a solution
Understanding the Difference between BUILD, REBUILD, CLEAN in Visual Studio
What is a Build Solution?
Build Solution – Builds any assemblies which have changed files. If an assembly has no changes, it won’t be re-built. Also, it will not delete any intermediate files.
- Modify some code in “
EmployeeDetails” library project, then BUILD solution. In the below screen shot, refer to the time stamp of DLL, EXE is updated. It happens for both projects as library project is referred in WPF application.
Figure 3: Assemblies, EXE gets complied after code changes on BUILD solution
Now modify or add some code in “
EmployeeDetails.UI” WPF project. Build this project to see what happens. Only WPF project gets complied or built. Figure 4 shows that only code changes gets built, not all projects.
Figure 4: Code changed in WPF will be complied when we BUILD it.
What is Rebuild Solution?
Rebuild solution will clean and then build the solution from scratch, ignoring anything it’s done before.
Right click on the solution name “
CleanBuildSolution”. What it does is deletes all the assemblies, EXEs and referred files to compile again. The screenshot below shows this:
Figure 5: Shows time stamp on assemblies, EXE in folder indicating all were deleted & recompiled
What is Clean Solution?
Clean Solution will delete all compiled files (i.e., EXEs and DLLs) from the bin/obj directory.
Right click on solution “
CleanBuildSolution” or WPF project “
EmployeeDetails.UI” and click on CLEAN. This will delete all the compiled files from BIN/ OBJ directory. This is quite important especially when we are working on large of inter linked projects. There is no files in BIN/ OBJ folders to show screen shot.
This Visual Studio’s feature is one of the best among its numerous features. Let's Clean, Build and Rebuild solutions everyday!!! CodeProject
The post Understanding Clean, Build and Rebuild in Visual Studio appeared first on Mithunvp.com.