In my profile I've got the following function:
function Start-VS {
param ([string]$sln, [switch]$UseNineteen )
if ($UseNineteen) {
$vs = "c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\devenv.exe"
$vsWorkDir = "c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\"
}
else {
$vs = "C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\devenv.exe"
$vsWorkDir = "C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\"
}
if (-Not ([string]::IsNullOrEmpty($sln))) {
$TestP = (Test-Path $sln)
if ( $TestP -eq $True) {
$FullPath = Convert-Path $sln
Start-Process $vs -WorkingDirectory $vsWorkDir -ArgumentList $FullPath
}
else {
Write-Output $FullPath
Write-Output "Please use a correct pathway to a solution file"
}
}
else {
Start-Process $vs -WorkingDirectory $vsWorkDir
}
}
To call it from the PS prompt I'm doing the following:
start-vs -sln "C:\demos\m02 arrays\Example.sln"
Visual studio opens but complains that it cannot find the files - I understand it is because of the space in m02 arrays - how do I alter the function so that it can handle spaces?