views:

2323

answers:

8

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 everyhing (sometimes it's the only way to force visual studio to forget all about previous builds).

Is there a quick way to accomplish this (with a bat file for example) without having to write a .net program?

+4  A: 

Is 'clean' not good enough? Note that you can call msbuild with /t:clean from the command-line.

Brian
In my experience, "clean" is often not good enough.
Joel in Gö
indeed. sometimes it's necessary to delete those folders
MichaelD
A: 

I think you can right click to your solution/project and click "Clean" button.

As far as I remember it was working like that. I don't have my VS.NET with me now so can't test it.

dr. evil
+3  A: 

something like this should work in a batch file - just please run it somewhere safe first to test it!

FOR /F "tokens=*" %%G IN ('DIR /B /AD /S bin') DO RMDIR /S /Q "%%G"
FOR /F "tokens=*" %%G IN ('DIR /B /AD /S obj') DO RMDIR /S /Q "%%G"

Personally I would rather use the msbuild command line clean method to do this though

Steve Willcock
thx for your answer.I get an error: %%G was unexpected at this time.
MichaelD
Hmm that's odd - it works fine on my machine (vista 64bit business) - I'll try it on an xp machine too.
Steve Willcock
Works ok for me on XP professional too - ah well :)
Steve Willcock
allright i got it to work. one strange issue is that when there is a bin folder in the root he doesn't delete anything. but that doesn't matter
MichaelD
have you got any idea how i let the script search in a folder other than it's running from?
MichaelD
got it, by doing:r:FOR /F "tokens=*" %%G IN ('DIR /B /AD /S obj') DO RMDIR /S /Q "%%G"FOR /F "tokens=*" %%G IN ('DIR /B /AD /S bin') DO RMDIR /S /Q "%%G"Pause
MichaelD
Thankyou Steve :)
Pondidum
+1  A: 

On our build server, we explicitly delete the bin and obj directories, via nant scripts.

Each project build script is responsible for it's output/temp directories. Works nicely that way. So when we change a project and add a new one, we base the script off a working script, and you notice the delete stage and take care of it.

If you doing it on you logic development machine, I'd stick to clean via Visual Studio as others have mentioned.

Simeon Pilgrim
sometimes i just have to be sure that all builds are completely new. I can't trust clean solution for doing that.deleting bin and obj has often proven more reliable
MichaelD
For us, only builds from the 'build machine' are tested, or used in production, so the developers don't have must be 'all clean' type issues, and the build server does that. Also means no one developer is needed to make a full build.
Simeon Pilgrim
What is the easiest way to do this with nant? I have A hierarchy of a couple dozen projects and I'd rather not misfire on a delete script. =)
Mike
We have many executables/dlls 'asset' built, so per asset we have a nant script that builds it. For each one there is a Delete section where we place a line for each debug/release bin/obj directory we want deleted.
Simeon Pilgrim
A: 

I actually hate obj files littering the source trees. I usually setup projects so that they output obj files outside source tree. For C# projects I usually use

 <IntermediateOutputPath>..\..\obj\$(AssemblyName)\$(Configuration)\</IntermediateOutputPath>

For C++ projects

 IntermediateDirectory="..\..\obj\$(ProjectName)\$(ConfigurationName)"
Juozas Kontvainis
A: 

We have a large .SLN files with many project files. I started the policy of having a "ViewLocal" directory where all non-sourcecontrolled files are located. Inside that directory is an 'Inter' and an 'Out' directory. For the intermediate files, and the output files, respectively.

This obviously makes it easy to just go to your 'viewlocal' directory and do a simple delete, to get rid of everything.

Before you spent time figuring out a way to work around this with scripts, you might think about setting up something similar.

I won't lie though, maintaining such a setup in a large organization has proved....interesting. Especially when you use technologies such as QT that like to process files and create non-sourcecontrolled source files. But that is a whole OTHER story!

pj4533
A: 

http://vsclean.codeplex.com/

Command line tool that finds Visual Studio solutions and runs the Clean command on them. This lets you clean up the /bin/* directories of all those old projects you have lying around on your harddrive

Joel Martinez
+1  A: 

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
Jhonny D. Cano -Leftware-