Skip to content

Instantly share code, notes, and snippets.

@RefusesNames
RefusesNames / Initialize-VS.ps1
Created May 28, 2024 20:26
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'