Running Open-VisualStudio
, or the vs
alias, in any folder will open the first *.sln
found in the stable version of Visual Studio. Using the -pre
flag will use the prerelease version that's installed.
Created
July 22, 2022 20:15
-
-
Save xt0rted/a2798b530aab9ff3ec3584ec90e1c452 to your computer and use it in GitHub Desktop.
Shortcut to open the first .sln found in Visual Studio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Open-VisualStudio { | |
Param( | |
[switch] $prerelease | |
) | |
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" | |
if (!(Test-Path $vswhere)) { | |
Write-Host "vswhere must be installed to use this command" -ForegroundColor Red | |
return | |
} | |
$path = Convert-Path . | |
$sln = Get-ChildItem -Path $path\* -Include *.sln | Select-Object -First 1 | |
if (!$sln) { | |
Write-Host "No .sln file found" -ForegroundColor Red | |
return | |
} | |
if ($prerelease) { | |
$devenv = & $vswhere -latest -prerelease -property productPath | Select-Object -First 1 | |
} else { | |
$devenv = & $vswhere -latest -property productPath | Select-Object -First 1 | |
} | |
if (!$devenv) { | |
Write-Host "Visual Studio was not found" -ForegroundColor Red | |
return | |
} | |
& $devenv $sln | |
} | |
New-Alias -Name vs -Value Open-VisualStudio -Scope Script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment