Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

Understanding Clean, Build and Rebuild in Visual Studio

, 4 Oct 2013 CC (ASA 3U)
Rate this:
Please Sign up or sign in to vote.
There isn’t any DOT NET developer using Visual Studio as IDE hasn’t used Clean, Build and Rebuild features as part of the Solution Explorer. They come handy when we work on large projects having multiple references, projects which get updated… Continue Reading →The post Under

There isn’t any DOT NET developer using Visual Studio as IDE hasn’t used Clean, Build and Rebuild features as part of the Solution Explorer. They come handy when we work on large projects having multiple references, projects which get updated very often or hardly updated with any code changes.

Recently i have being dealing with solution having more than 40 projects with lots of proxy service references. Source code in TFS gets checked almost every hour. Sometimes it says “BUILD SUCCEED” but on running the application, every things breaks down.

I just CLEAN Solution, then REBUILD or BUILD Solution, it starts working. This isn’t magic in Visual Studio nor it’s best practice to followed but its worth knowing that what actually Clean, Build & Rebuild in Visual Studio main functionality is.

Creating a solution in Visual Studio with different projects

  •  Created a blank solution “CleanBuildSolution” in Visual Studio 2012.
  • Add class library project to it “EmployeeDetails” to above solution. It has three files EmployeeObject.cs, EmployeeOperations.cs, EmployeeStore.xml
  • Add WPF project “EmployeeDetails.UI”. At present it doesn’t contain any reference to class library project created above. Note: Any project template can be used Windows Forms, ASP.NET, Console etc

    create solution add projects

    Figure 1: Solution having 2 projects created by following above steps

When we check the folders in this solution, it contains only files which we created in above steps along with project files. Now then Build solution by 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 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. Below screen shot shows DLL, EXE, XML files of both projects.
Project-reference-Build

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 will not delete any intermediate files.

  • Modify some code in “EmployeeDetails” library project, then BUILD solution. In the below screen shot, refer time stamp of DLL, EXE its updated. It happens for both projects as library project is referred in WPF application.
Project-reference-Build-codeChange

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 builded. Figure 4 shows that only code changes gets build not all projects.
Project-reference-Build-codeChange-wpf

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, exe’s and referred files to compile again. Screen shot below shows this
Project-reference-ReBuild

Figure 5: Shows time stamp on assemblies, exe in folder indicating all where deleted & recompiled

What is Clean Solution?

Clean Solution will delete all compiled files (i.e., EXE’s and DLL’s) 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 esp 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 best among its numerous features. Lets Clean, Build and Rebuild solutions everyday !!!

Reference: Building and Cleaning Projects and Solutions in Visual Studio

The post Understanding Clean, Build and Rebuild in Visual Studio appeared first on Mithunvp.com.

License

This article, along with any associated source code and files, is licensed under The Creative Commons Attribution-Share Alike 3.0 Unported License

Share

About the Author

I am Mithun Pattankar, a Software Professional on day job and blogger at nights. My interests are in Microsoft Technologies like DotNet, Visual Studio, ASP.NET, WPF, WCF, C#, HTML5
 
URL: www.mithunvp.com
Follow on   Twitter   Google+

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web03 | 2.8.141015.1 | Last Updated 4 Oct 2013
Article Copyright 2013 by Mithun Pattankar
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid