Collapse all the folders being installed after the installation

Jan 18, 2012 at 7:38 PM

I have a package which gets bunch of folders and files into the application solution and when it is done installing, all of the folders are left open. As you know, there is not collapse all inside visual studio 2010 as in vs 11, so it is annoying.

I thought I could collapse all the folders through install.ps1 file and indeed I got something working (well, I cheated a bit from razorgenerator nuget package :)). Here is what I have done:

param($installPath, $toolsPath, $package, $project)

function Resolve-ProjectName {
        [parameter(ValueFromPipelineByPropertyName = $true)]
    if($ProjectName) {
        Get-Project $ProjectName
    else {

function Get-Folders {
    Process {
        if ($_.Kind -eq "{6BB5F8EF-4483-11D3-8BCF-00C04F8EC28C}") {
            $_.ProjectItems | Get-Folders

function Get-RelativePath {
    param($projectPath, $file) 
    $filePath = $file.Properties.Item("FullPath").Value
    $index = $filePath.IndexOf($projectPath)
    if ($index -ge 0) {

function Get-TinyMCEFolders { 

    (((Resolve-ProjectName $ProjectName).ProjectItems | where { $_.Name -eq "Scripts" }).ProjectItems | Where { $_.Name -eq "tinymce" }).ProjectItems | Get-Folders

$solutionExplorer = ($dte.Windows | Where { $_.Type -eq "vsWindowTypeSolutionExplorer" }).Object
$project = (Resolve-ProjectName $projectName)
$projectPath = [IO.Path]::GetDirectoryName($project.FullName)
$ProjectName = $project.Name
$SolutionName = [IO.Path]::GetFileNameWithoutExtension($dte.Solution.FullName)

Get-TinyMCEFolders | % {
    $relativePath = Get-RelativePath $projectPath $_
    if ($relativePath) {
        try {
            $solutionExplorer.GetItem("$SolutionName\$ProjectName$relativePath").UIHierarchyItems.Expanded = $false
        } Catch  [system.exception] {
            Write-Host "Your package successfully installed but there was a problem while collapsing a folder:"
            Write-Host "Path: $SolutionName\$ProjectName$relativePath"

I know the code is so ugly :) besides that, I sometimes get errors with this approach. You can download the package and see it yourself:

Install-Package TinyMCE

Do you think if there is a better way? Or can you look at the code and provide some alternatives.

Thanks in advance!

Jan 18, 2012 at 7:51 PM

We receieved a bunch of complaints about this and ended up doing it as part of NuGet.VisualStudio 8f0475464e71
Should start seeing your folder status (expanded\collapsed) preserved as part of the next release.

Jan 19, 2012 at 1:12 AM

When did we receive a "bunch of complaints"? AFAIK, there are only a few complaints.

Jan 19, 2012 at 1:19 AM

I stand corrected. It wasn't a bunch of complaints, just a few. Because arbitrary measurement units need to be quantified :)

Jan 19, 2012 at 8:36 AM

Thanks a lot guys. That would be nice to have it OOB.

But what is the problem with above code? Sometimes I get an error while I try to collapse a folder.