• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 $vsInstallPath=& "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -version 16.0  -property installationpath
2 Write-Output "vswhere.exe installPath: $vsInstallPath"
3 $vsInstallPath =  if ("$vsInstallPath" -eq "" ) { "C:\BuildTools" } else { "$vsInstallPath" }
4 Write-Output "Final installPath: $vsInstallPath"
5 Import-Module (Join-Path $vsInstallPath "Common7\Tools\Microsoft.VisualStudio.DevShell.dll")
6 # https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B
7 # VS2015 14.0 use -vcvars_ver=14.0
8 # VS2017 14.1 to 14.16 use -vcvars_ver=14.16
9 # VS2019 14.20 to 14.29 use -vcvars_ver=14.29
10 # VS2022 14.30 to 14.38 (not finished yet) use -vcvars_ver=14 to choose the newest version
11 
12 $vcvars_ver_arg=$args
13 if ($null -eq $vcvars_ver_arg[0]) {
14   $vcvars_ver_arg="-vcvars_ver=14"
15 }
16 
17 Enter-VsDevShell -VsInstallPath $vsInstallPath -SkipAutomaticLocation -DevCmdArguments "$vcvars_ver_arg -arch=x64 -no_logo -host_arch=amd64"
18