Click here to Skip to main content
15,867,686 members
Articles / Programming Languages / C#

C# bin vs obj Folder

Rate me:
Please Sign up or sign in to vote.
4.60/5 (38 votes)
21 Jun 2021CPOL2 min read 45.6K   23   11
bin vs obj folder in C#

When you compile C# programs, you would see 2 folders “bin” and “obj”. In this article, we will try to understand the difference and importance of these folders.

Both these folders have compiled IL code, but the question is why not just one folder and why two folders?

Image 1

We have two folders because the compilation process goes through two steps, compiling and linking. See the below diagram.

  • In compiling phase, every code file is compiled into individual compiled units. So if you have two code files, two independent compiled codes will be generated.
  • In linking phase, all these compiled code files are linked and compiled into a single unit assembly which can be a DLL or EXE.
Image 2

If you compare both the folders (see the below image), you will find more files in “obj” folder as compared to “bin” folder. We have more files in “obj” folder because it creates separate compiled code files for each source code file.

Image 3

So the next question which comes to our mind is why do we need compiling in two phases, why not just do it in one go. By doing the two phase compiling, we achieve incremental or conditional compiling.

When we work with big projects, we will have a lot of code files and we would like to only compile those code files which have changed. In the “obj” folder we have entry of each code file compilation. So we can know from the same which files exactly have changed, thus making compiling fast.

Image 4

In summary, in “obj” folder, we have compiled files for each source code file and in “bin” folder, we have a single unit which links all individually compiled code files.

Below is a 10 minute YouTube video which demonstrates how both these folders look like and how incremental compilation happens.

Image 5

For Further reading do watch  the below interview preparation videos and step by step video series.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect https://www.questpond.com
India India

Comments and Discussions

 
GeneralWhy this article get so many upvotes? Pin
wmjordan27-Jun-21 21:04
professionalwmjordan27-Jun-21 21:04 
GeneralRe: Why this article get so many upvotes? Pin
Shivprasad koirala27-Jun-21 21:26
Shivprasad koirala27-Jun-21 21:26 
GeneralRe: Why this article get so many upvotes? Pin
wmjordan28-Jun-21 21:49
professionalwmjordan28-Jun-21 21:49 
QuestionDuplicate DLL or EXE files Pin
JNygren23-Jun-21 17:05
JNygren23-Jun-21 17:05 
AnswerRe: Duplicate DLL or EXE files Pin
wmjordan27-Jun-21 21:08
professionalwmjordan27-Jun-21 21:08 
Questionneed to remove all obj folders Pin
martinrj3022-Jun-21 22:39
martinrj3022-Jun-21 22:39 
I would like to add, that obj folders can get a bit 'muddled up' and confused.

If multiple visualstudio's are open and the 'add win to config' error appears during a project rebuild.
The fix is to close all the visualstudio's
Open Explorer to the solution folder
Search for: obj AND kind:folder
and delete all the obj folders

This will clear the corrupt obj cache and allow you to rebuild your solution.
GeneralRe: need to remove all obj folders Pin
Kent K23-Jun-21 9:46
professionalKent K23-Jun-21 9:46 
AnswerRe: need to remove all obj folders Pin
tbayart28-Jun-21 11:50
professionaltbayart28-Jun-21 11:50 
GeneralMy vote of 5 Pin
rich.v222-Jun-21 11:08
rich.v222-Jun-21 11:08 
Generaldoes Visual Studio use NMAKE utility to implement this? Pin
Southmountain16-Jun-18 9:24
Southmountain16-Jun-18 9:24 
GeneralRe: does Visual Studio use NMAKE utility to implement this? Pin
Richard MacCutchan21-Jun-21 22:40
mveRichard MacCutchan21-Jun-21 22:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.