Skip to content

Instantly share code, notes, and snippets.

@RefusesNames
Created May 28, 2024 20:26
Show Gist options
  • Select an option

  • Save RefusesNames/11a97ca77d39724f1a0d30ad81db7cd1 to your computer and use it in GitHub Desktop.

Select an option

Save RefusesNames/11a97ca77d39724f1a0d30ad81db7cd1 to your computer and use it in GitHub Desktop.
This function updates paths and sets environment variables the same way a Visual Studio developer console does
function Initialize-VS {
$vsPath = & (Join-Path ${env:ProgramFiles(x86)} "\Microsoft Visual Studio\Installer\vswhere.exe") -property installationpath
if ($vsPath -is [array]) {
$last = $vsPath | Select -Last 1
Import-Module (Join-Path $last "Common7\Tools\Microsoft.VisualStudio.DevShell.dll")
Enter-VsDevShell -VsInstallPath $last -SkipAutomaticLocation -DevCmdArguments '-arch=amd64 -no_logo'
} else{
Import-Module (Join-Path $vsPath "Common7\Tools\Microsoft.VisualStudio.DevShell.dll")
Enter-VsDevShell -VsInstallPath $vsPath -SkipAutomaticLocation -DevCmdArguments '-arch=amd64 -no_logo'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment