I work with multiple projects, and I want to recursively delete all folders with the name \'bin\' or \'obj\' that way I am sure that all projects will rebuild everything (so
I wrote a powershell script to do it.
The advantage is that it prints out a summary of deleted folders, and ignored ones if you specified any subfolder hierarchy to be ignored.
Something like that should do it in a pretty elegant way, after clean target:
<Target Name="RemoveObjAndBin" AfterTargets="Clean">
<RemoveDir Directories="$(BaseIntermediateOutputPath)" />
<RemoveDir Directories="$(TargetDir)" />
</Target>
I found this thread and got bingo. A little more searching turned up this power shell script:
Get-ChildItem .\ -include bin,obj -Recurse | ForEach-Object ($_) { Remove-Item $_.FullName -Force -Recurse }
I thought I'd share, considering that I did not find the answer when I was looking here.
I use to always add a new target on my solutions for achieving this.
<Target Name="clean_folders">
<RemoveDir Directories=".\ProjectName\bin" />
<RemoveDir Directories=".\ProjectName\obj" />
<RemoveDir Directories="$(ProjectVarName)\bin" />
<RemoveDir Directories="$(ProjectVarName)\obj" />
</Target>
And you can call it from command line
msbuild /t:clean_folders
This can be your batch file.
msbuild /t:clean_folders
PAUSE
This is my batch file that I use for deleting all BIN and OBJ folders recursively.
@echo off
@echo Deleting all BIN and OBJ folders...
for /d /r . %%d in (bin,obj) do @if exist "%%d" rd /s/q "%%d"
@echo BIN and OBJ folders successfully deleted :) Close the window.
pause > nul
Have a look at the CleanProject, it will delete bin folders, obj folders, TestResults folders and Resharper folders. The source code is also available.