Search code examples
visual-studio-2017devenv

reliable way to find the location devenv.exe of Visual Studio 2017


I need to run scripts that build a visual studio solutions using devenv.exe (or devenv.com for that matter). For visual studio 2015 there was an environment variable %VS140COMNTOOLS% that I could use to find the install location of devenv. Since there is no %VS150COMNTOOLS% for Visual Studio 2017, what would be a reliable way to find the install location of devenv in a script (bat or powershell).


Solution

  • You can use vswhere.exe or powershell to find your Visual Studio instances:

    for /r "usebackq tokens=1* delims=: " %%i in (`vswhere.exe -latest -requires Microsoft.VisualStudio.Workload.NativeDesktop`) do (
        if /i "%%i"=="installationPath" set dir=%%j
    )
    

    and

    Install-Module VSSetup -Scope CurrentUser
    Get-VSSetupInstance | Select-VSSetupInstance -Latest -Require Microsoft.VisualStudio.Component.VC.Tools.x86.x64
    

    The path to specific workloads can be found through this api as well.

    https://blogs.msdn.microsoft.com/vcblog/2017/03/06/finding-the-visual-c-compiler-tools-in-visual-studio-2017/