Programmatically finding the VS2017 installation directory

前端 未结 10 1222
梦谈多话
梦谈多话 2020-12-06 17:49

With previous versions of VS you could query the registry to determine the installation directory for VS:

HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Visu

10条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 18:39

    Well, vswhere.exe doesn't really supply more than the Visual Studio edition installation path. Here's my .profile file Interix snippet from 2008 doing the same with a minor update (shell script):

    if [[ -n $PROCESSOR_ARCHITEW6432 || $PROCESSOR_ARCHITECTURE != "x86" ]]; then
      hkeybase='HKLM\SOFTWARE\Wow6432Node\Microsoft\'
    else
      hkeybase='HKLM\SOFTWARE\Microsoft\'
    fi
    for vsver in "15.0" "14.0" "12.0" "11.0" "10.0" "9.0" "8.0"; do
      _vsinstalldir=$(reg.exe query ${hkeybase}'VisualStudio\SxS\VS7' -v $vsver 2>/dev/null \
       | sed -n 's|.*REG_SZ *\([ [:print:]]*\).*|\1|p' | sed 's|\\|/|g')
    if [[ -n $_vsinstalldir ]]; then break; fi
    done; unset vsver
    

    That's enumerating Visual Studio installations favouring the latest in registry key

    HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VS7
    

    Still working for Visual Studio 2017. Would be easy to translate to cmd syntax. To query the registry is simpler and doesn't require vswhere.exe in your path, thus favourable IMO.

    Now finding the current Visual C++ instance and the SDKs is another task entirely. :D

    Common output in case you wonder:

    C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/
    

提交回复
热议问题