Recursively remove bin/obj folders Powershell

To really "clean" that solution/project

Posted by admin on April 24, 2024

TLDR

Run these commands to remove all the bin and obj folders.

get-childitem $path -include bin -recurse | remove-item
get-childitem $path -include obj -recurse | remove-item

Special thanks to this post for giving me the answer

Why?

Sometimes in the .NET solution, even the batch build's clean and rebuild commands do not clear out all files from the bin and obj folders. Reason being is the msbuild will not remove files it is not aware.

The exact scenario I need to solve was that I had changed the version number of a nuget library but when I rebuilt the solution, the old assembly file was in the bin folder and that was used rather that you new downgraded version.

More precisely in my case, I had repackages a new version of a local nuget package using the same exact version number. Because...reasons.

Conclusion

When it doubt, clean it out.

If you found value in this post, consider following me on X @davidpuplava for more valuable information about Game Dev, OrchardCore, C#/.NET and other topics.