Skip to content

Instantly share code, notes, and snippets.

@AmSmart
Last active November 30, 2020 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AmSmart/c8dd1b604695866fc26601c66bef60ea to your computer and use it in GitHub Desktop.
Save AmSmart/c8dd1b604695866fc26601c66bef60ea to your computer and use it in GitHub Desktop.
vs2019here.ps1
# This script helps to open a VS solution in VS2019, can be modified for other VS versions.
# Usage:
# 'vs2019here' --> Opens a VS solution in the current working directory, if any
# 'vs2019here .' --> Opens VS in the current working directory (folder view mode)
# 'vs2019here path' --> Opens a VS solution in the specified path(folder view mode if path is not a isn't a ".sln" file)
# 'vs2019here -p path' --> Opens a VS solution in the specified path(folder view mode if path isn't a ".sln" file)
$vs19 = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\devenv.exe"
$vs19WorkDir = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE"
$filesInCwd = Get-ChildItem(Get-Location)
$solutionPath = ""
if (-not ([string]::IsNullOrEmpty($args[0])))
{
$solutionPath = $args[0]
}
if($args[0] -eq "-p")
{
$solutionPath = $args[1]
}
if($args[0] -eq ".")
{
$solutionPath = Get-Location
}
if($solutionPath -eq "")
{
for ($i=0; $i -lt $filesInCwd.Count; $i++)
{
$extn = [IO.Path]::GetExtension($filesInCwd[$i])
if ($extn -eq ".sln" )
{
$solutionPath = $filesInCwd[$i]
Write-Host "$($solutionPath)"
break
}
}
}
Start-Process $vs19 -WorkingDirectory $vs19WorkDir -ArgumentList `"$($solutionPath)`"
#CREDITS
### This code is inspired/based on a StackOverflow question and Mathias R. Jessen's answer to it
### Link to the StackOverflow post: https://stackoverflow.com/a/60870266/8606289
### Written by Emmanuel O. Adebiyi: Github - @AmSmart, Twitter - @SmartE03, Reddit - @SmartE03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment