Anders Forsgren
Anders Forsgren

Reputation: 11111

How can I do a complete clean of my VS 2012 solution?

Is there any way I can clean a VS solution completely? By completely I mean not just removing the current output for the projects built by the Active configuration. I mean cleaning out all output and intermediate files, for all build configurations.

Even after I change build output paths, I want to delete the ouput from the previous output paths.

Example scenario: I check out a source tree and make a release build, then a debug build. Now I have \bin\Debug directories and bin\Release directories, as well as \obj directories. I then want to clean the output for both configurations.

Maybe Subversion is a better tool for this, e.g. delete everything that isn't under source control? Otherwise, I suppose a batch file that cleans out obj, bin and TestResults directories recursively could do it, and I could bind a VS menu item to this tool.

I'm using SVN 1.7 and VS 2012.

Has anyone already created such a tool using VS, SVN, PowerShell or a windows batch file?

Upvotes: 3

Views: 1749

Answers (3)

watbywbarif
watbywbarif

Reputation: 7017

If you need some fine grained approach to clean only selected solutions or configurations you can use script like this:

$devenvPath = "`"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv`""
$configuration = (
    "Release",
    "Debug"
)
$platform = (
    "x86",
    "x64"
)
$sln = (
    "Sln1Path.sln",
    "Sln2Path.sln"
)
foreach ($c in $configuration)
{
    foreach($p in $platform)
    {
        foreach($s in $sln)
        {
            $pc = $c + "|" + $p
            $arg = "`"$s`" /clean `"$pc`""
            $cmd = "Start-Process -FilePath $devenvPath -ArgumentList `'$arg`' -Wait -NoNewWindow"
            echo $cmd
            $proc = invoke-expression $cmd
            echo "`n`n`n`n`n"
        }
    }
}

Upvotes: 0

Sameer Singh
Sameer Singh

Reputation: 1366

Whenever I add a brand new solution to SVN, I ensure that I mark the bin\ and obj\ folders of each project as ignored before I commit. I do the same for the .suo file (personal preference). That way, when I need to clean up any intermediate and build outputs, I just TortoiseSVN -> SVN Clean up ... and check Delete ignored files and folders:

TortoiseSVN 1.7's Clean up Dialog

This article by Jeff Atwood influenced me. Relevant portion:

How long does it take for you to get a new team member working productively on your project? If the answer is more than one day, you have a problem.

I want to be able to check out a solution and have it build first time. I also want to be able to easily make my checkout "like new" which is why I use SVN Cleanup so much.

One caveat is that you will probably have to close down Visual Studio before performing an SVN Cleanup so that none of the files in your bin\ and obj\ folders have been locked by it.

Hope this helps.

Upvotes: 5

RinoTom
RinoTom

Reputation: 2326

We can assume you solution files stay in a folder named "MySolutionFolder" and it is code versioned under Subversion (SVN) and you have TortoiseSVN client installed in your local machine to manage the code versioning.

Then, right click the folder where you chekced out your code folder "MySolutionFolder". Then go for the option TortoiseSVN --> Properties. In the new window opened, click 'New' button go for the option 'Advanced' in popup list. And enter the following in the new window appears and save it.

SVN Ignore Window

After, that just right the "MySolutionFolder" again and select the option, TortoiseSVN --> Revert and in the new window opened, click 'Delete unversioned items'. On clicking that it will list all the unversioned files including 'bin' and 'obj' folders for whole solution since it was included in svn:ignore list and other unversioned files as well. Select the items you want to delete from that and press 'OK'. Your code output will be cleaned by that.

This svn:ignore property you can even commit along with your code so that other users also get the advantage of this.

Upvotes: 2

Related Questions