Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the 'obj' directory for in .NET? [duplicate]

Tags:

c#

.net

What exactly is the purpose of the 'obj' directory in .NET?

like image 699
Andrew Jones Avatar asked Oct 24 '08 10:10

Andrew Jones


People also ask

What is the use of obj folder?

"obj" folder is used to store temporary object files and other files used to create the final binary.

Can I delete the obj folder?

The bin and obj folders are usually safe to delete since they are automatically generated when the solution/project is being build by Visual Studio/MSBuild.

What is .obj file Visual Studio?

Object files contain relocatable machine code that is generated from your source code. Visual Studio creates one . obj file per each . cpp file. Then depending on the project (executable, static/dynamic library) you can get relocatable or non-relocatable code.

What is the purpose of the OBJ folder in a project?

The obj folders are really intended to hold intermediate things. But in C# projects, there will be no *.obj files that serve as intermediate compilation result of source code files like C/C++. Why is there a copy of the DLL or EXE file in the obj folder, as well as the bin folder?

What is the difference between bin and OBJ in Visual Studio?

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.

What is the output path of OBJ folder in Visual Studio?

The default output path for any project is Visual studio is bin/Debug, but I have noticed that obj folder is also generated which again contains dll and pdb files. Can someone tell me why is this folder generated?

Do I need to look into the OBJ directory in WPF?

Now, as the files are intermediate, you don't need to look into this directory. Well, almost. Sometimes, this is useful to learn how some things work. One example is this: WPF project generates some common code and compiles with that generated code, so it is placed in the "obj" sub-directory. That includes the Main method and some other stuff.


2 Answers

The "obj" folder is used to store temporary object files and other files used in order to create the final binary during the compilation process.

The "bin" folder is the output folder for complete binaries (assemblies).

like image 200
splattne Avatar answered Sep 20 '22 13:09

splattne


In addition to splattne's answer, I believe the reason for having it (and not cleaning it up after the build) is to support incremental compilation. If you've already compiled 100 classes and change one of them, it's much more efficient to just recompile the code for the one changed class and reassemble the exe/dll from a mixture of the new and old code.

Of course, incremental compilation is a lot more complex than just that - it has to keep track of everything so it can detect when it needs to recompile a class even if that class itself hasn't changed. (e.g. if a new overload becomes available in a class - some callers may need to be recompiled.)

like image 36
Jon Skeet Avatar answered Sep 20 '22 13:09

Jon Skeet