Remove bin and obj directory in .NET project

In .NET projects, the obj and bin folders are automatically generated by the .NET build system.

  • obj Folder:

    • The obj folder is a temporary folder used by the build process. It contains intermediate files that are generated during the compilation process. These files include object files, generated code, and other temporary data needed to build the final output.

    • The contents of the obj folder are typically specific to the current build configuration (e.g., Debug, Release) and platform (e.g., x86, x64).

  • bin Folder:

    • The bin folder contains the final output of your build process. This includes the compiled assembly files (e.g., .dll, .exe), as well as any other files that are part of your project and are set to be copied to the output directory (e.g., configuration files, resources).

    • Similar to the obj folder, the bin folder is also organised by build configuration and platform.

  • So let's see how we can remove them from all solutions by just one click

  1. Create a file called clearDerivedData.sh

     # https://www.geeksforgeeks.org/creating-and-running-bash-and-zsh-scripts/
    
     read -p "Path to directory whose obj and bin want to clear?: " dirpath;
    
     # This will clear the obj and bin from nexgen projects
     echo "bin and obj folders will be cleared"
    
     directory_array=("NAMPhone/bin" 
         "NAMPhone/obj" 
         "Phone/Droid/obj" 
         "Phone/Droid/bin" 
         "Phone/iOS/bin" 
         "Phone/iOS/obj" 
         "Phone/OneSignalNotificationServiceExtension/bin"
         "Phone/OneSignalNotificationServiceExtension/obj"
         "Tablet/Droid/bin" 
         "Tablet/Droid/obj" 
         "Tablet/iOS/bin" 
         "Tablet/iOS/obj"
         "Tablet/OneSignalNotificationServiceExtension/bin"
         "Tablet/OneSignalNotificationServiceExtension/obj")
    
     for path in "${directory_array[@]}"; do
         # echo "$dirpath/$path"
         rm -rf "$dirpath/$path"
     done
    
     echo "Cleared obj and bin contents"
    
  2. Than run chmod +x clearDerivedData.sh

  3. Open the terminal

  4. Drag and drop clearDerivedData.sh in there

  5. When it asks you for path just drag and drop the folder from which you want to delete bin and obj

  6. That's it, it will clear those folders for you!!!

Enjoy 😉