Quick way to clean temp files & directories in Xamarin projects

Stop manually deleting the bin & obj folders from today

The First Prototype
2 min readSep 13, 2020


If you have done a weeks’ worth of Xamarin mobile development, you know the need to frequently delete the bin & obj folders in each sub-directory of your solution. This tedious process essentially clears the cache and deletes any improperly built code, so that you can recompile your code, and this magically solves half the problems you face.

All these 11722 unneeded auto-generated files deleted with one command

How does this work?

To achieve this we are going to take advantage of how projects with git version controlling setup correctly, will only “track” the necessary files that are not “auto-generated”. So in order to make this work, you need a file named .gitignore file in your solution directory. The GITIGNORE is a text file that is hidden, thanks to the . in front of it. If you initialized your solution using a git client with a VisualStudio gitignore, this step will already be done for you. If not, just copy the contents from here, and place it in the file.

Remember to always commit all the changes that you need before you perform the next step, since it can occasionally delete some important files that you need.

Alright, what’s the command?

Open your terminal to the main folder and run this command:

git clean -fxd

and voilà! Look at the beautiful way all those temp files get deleted, without having to manually delete them. A lot of these files are not otherwise removed, even with a “Clean All”.

Then, to restore back needed nuget packages, you can just run nuget restore in your terminal. Now reopen your solution, rebuild the app, and any error needing a clear of cache should be resolved.

GIF Showing the Gitignore being added, and the effect of the Git Clean command

Let me know if there are any other quick tips and commands you use, so I can add them here to share it with the others! Sameer Khandekar just told me about his Visual Studio extension that does this, but I haven’t tried it yet.