Skip to content

Instantly share code, notes, and snippets.

@refactorsaurusrex
Last active February 1, 2024 03:21
Show Gist options
  • Save refactorsaurusrex/2a0d8efd88ceb30eb69488c1b11c7682 to your computer and use it in GitHub Desktop.
Save refactorsaurusrex/2a0d8efd88ceb30eb69488c1b11c7682 to your computer and use it in GitHub Desktop.
PowerShell function to open the first Visual Studio solution file found within the current directory.

What is this thing?

Rather than navigating around Windows explorer, looking for that pesky .sln file you want to open, why not just open in from your command line? This module allows you to type sln from your PowerShell terminal window to open the first .sln file found within the current directory or any of its children.

Installation (Option 1)

  1. Download this gist as a zip file.
  2. Extract the file to \Documents\WindowsPowerShell\Modules\Open-Solution.
  3. Restart PowerShell.
  4. Navigate to a directory that contains a Visual Studio solution file and type sln.
  5. Alternatively, type sln <PATH_TO_DIRECTORY_CONTAINING_VS_SOLUTION_FILE_AT_ANY_DEPTH>
  6. Profit!

Installation (Option 2)

  1. Run Install-Module -Name WhatsNew. https://github.com/refactorsaurusrex/whats-new
  2. Type sln.
  3. Profit!
@{
RootModule = 'Open-Solution.psm1'
ModuleVersion = '0.1.0'
GUID = '42f8cad0-c32a-4ccd-9401-de4bdbafdd65'
Author = 'Nick Spreitzer'
FunctionsToExport = @('Open-Solution')
AliasesToExport = @('sln')
}
function Open-Solution() {
param(
[string]$RootDirectory = ''
)
$solutions = Get-ChildItem -recurse -path "$RootDirectory*.sln"
if ($solutions.Count -eq 1) {
& $solutions.FullName
}
elseif ($solutions.Count -eq 0) {
write-host "I couldn't find any solution files here!"
}
elseif ($solutions.Count -gt 1) {
write-host "I found more than solution. Which one do you want to open?"
$solutions | ForEach-Object { write-host " - $($_.FullName)" }
}
}
Set-Alias sln Open-Solution
@refactorsaurusrex
Copy link
Author

refactorsaurusrex commented Feb 1, 2024 via email

@thwyster
Copy link

thwyster commented Feb 1, 2024

Oh sorry my ctrl v is wrong, i type the complete row:
Install-Module -Name WhatsNew. https://github.com/refactorsaurusrex/whats-new

https://github.com/refactorsaurusrex/whats-new shouldn't be in charge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment