Programmatically finding the VS2017 installation directory

前端 未结 10 1207
梦谈多话
梦谈多话 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:21

    We have only 3 Visual Studio editions.

    • \Community
    • \Professional
    • \Enterprise

    As such we can simplify everything a bit.
    Here some tested CMD script.

    @SET env_all_vs2017_root=%ProgramFiles(x86)%\Microsoft Visual Studio\2017
    @SET env_vs2017_path="%env_all_vs2017_root%\Professional"
    @IF NOT EXIST %env_vs2017_path%  SET env_vs2017_path="%env_all_vs2017_root%\Community"
    @IF NOT EXIST %env_vs2017_path%  SET env_vs2017_path="%env_all_vs2017_root%\Enterprise"
    @REM Let's fail laudly
    @IF NOT EXIST %env_vs2017_path%  SET "env_vs2017_path=Visual Studio 2017 install path was not found by %~nx0"
    
    @REM  You may want to remove quotes
    @SET unquoted=%env_vs2017_path:"=%
    
    
    @REM  And now let's see the result and PAUSE
    
    @ECHO VS 2017 install path is
    @ECHO %unquoted%
    
    @PAUSE
    

提交回复
热议问题