DEV Community

Sabah Shariq
Sabah Shariq

Posted on

Visual Studio: Build, Rebuild, Clean and Batch Build

Introduction

In this blog post we will look into the build configuration of our project or solution in Visual Studio application.

Visual Studio Logo

Build Configuration

The build solution will always perform an incremental build i.e. it will only build those files (dll and .exe) which have changed.

When we develop our .NET application in Visual Studio we see following build configuration:

  • Debug
  • Release VS Build Config Debug Release Folder Now, if we look into more details...

Debug

Debug mode allows developer to break the execution of program and step through the code. Compiled code dll in debug is not optimized. Therefore, size of dll file in debug mode is comparatively larger than release mode. Some additional instructions are added to enable the developer to set a breakpoint on every source code line like "symbolic information". For example, adding following code block will only execute in debug and in release mode this code block will get ignored.

#if DEBUG  
Console.WriteLine("Hello! This is Debug Mode");  
#endif 
Enter fullscreen mode Exit fullscreen mode

Release

This mode is for final deployment of the source code on production server. Release mode dll file contains optimized code, and it is generated for end user. Debugging symbol information is also gets omitted from the dll file in this mode.

Solution Structure

Rebuild Solution

Rebuild solution will delete all the files (dll and .exe) or "bin and obj" and perform build from scratch irrespective of whether the files are modified or not. Please note that "Rebuild" will clean then build each project, one at a time, rather than cleaning all and then building all projects.

Clean Solution

The clean solution will delete all the compiled files (dll and .exe) from "bin and obj" directories. You may notice that not all of the files are actually removed from the project folder. This might happen because clean only removes files that are associated with a build and not everything else.

Build vs. Rebuild vs. Clean

The difference lies in what happens in each build configuration
for every projects.

For example, if the solution has two projects: Project A & Project B and you perform rebuild operation, it will take Project A, clean the compiled files for Project A, and build it. After that, it will take Project B, clean the files for Project B, and build it.

On the other hand, if you do a clean and then build separately, it will first clean all compiled files (dlls and .exe) for both the projects – Project A & Project B and then it will build Project A first then Project B.

Batch Build

Batch Build

When we build our project our project in visual studio we can only build it into one configuration mode at a time like Debug or Release etc. So, if we want to build our project into multiple configuration i.e. Debug and Release or build the project for multiple platforms, such as x86 and x64, all at once at the same time then we can do that with Batch Build operation. Batch build allows you to build multiple configurations with a single command instead of building them individually.

To perform a batch build, you can go to the "Build" menu, select "Batch Build," and then select the configurations and platforms that you want to build.

Concluiton

In summary, it is important to keep in mind that what happens in each build configuration in Visual Studio and based on our requirement we can select how our project or solution can be build.

Top comments (2)

Collapse
 
codehaks profile image
Hakim

Useful information, I always how each option works, thanks

Collapse
 
sabahshariq profile image
Sabah Shariq

You are welcome..