Thursday, February 24, 2011

PowerShell script to find and open solution (.sln) files

Finding and opening Visual Studio solutions in multiple projects and branches can be painful at times. This simple script may help:

param([int]$OpenId)

$it = 0
$sln = dir -Filter *.sln -Recurse | 
    sort FullName |
    % { New-Object psobject -Property @{ Id = ++$it; Name = $_.Name; FullName = resolve-path -relative $_.FullName } }

if($OpenId)
{
    if($OpenId -lt 0 -or $OpenId -gt $sln.length)
    {
        throw "Invalid Id."
    }

    & $sln[$OpenId - 1].FullName
}
else
{
    $sln
}

0 comments:

Post a Comment