microsoft / vssetup.powershell

PowerShell module to interact with Visual Studio Setup
MIT License
233 stars 41 forks source link

Using 2019 BuildTools with 2017 compiler #59

Closed hjmallon closed 4 years ago

hjmallon commented 4 years ago

Visual Studio 2019 installer allows you to install different versions of the compiler. e.g.

MSVC v142 - VS 2019 C++ x64/x86 build tools (v14.24)
MSVC v141 - VS 2017 C++ x64/x86 build tools (v14.16)
MSVC v140 - VS 2015 C++ build tools (v14.00)

I have all three of these installed but:

> Get-VSSetupInstance -All

InstanceId          : 13fe59b9
DisplayName         : Visual Studio Build Tools 2019
InstallationVersion : 16.4.29728.190
InstallationPath    : C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools
InstallDate         : 04/02/2020 16:22:55

How do I therefore set up a powershell session so that I can use the 2017 tools?

heaths commented 4 years ago

There's only once Visual Studio Build Tools instance installed. Installing different versions of the compiler/toolset are features in that instance. If you want to see features installed, expand the Packages property. You can filter on type (e.g. 'Component') and partial name, like 'MSVC' using cmdlets like where-object.

hjmallon commented 4 years ago

I think I may have misunderstood. Is it possible to use this project to set up the environment like vcvarsall.bat used to do? I am trying to use 2019 tools (with 2015 and 2017 compilers installed) and make powershell instances where I can use cmake with each version.

Using CMD and 2017 tools (with 2015 compiler installed) I was able to choose which tools to use with vcvarsall.bat.

hjmallon commented 4 years ago

For anyone looking at this in the future. The answer is to use CMAKE_GENERATOR_TOOLSET. https://cmake.org/cmake/help/latest/variable/CMAKE_GENERATOR_TOOLSET.html#variable:CMAKE_GENERATOR_TOOLSET

cmake -Ax64 -G"Visual Studio 16 2019" -Tv141 ../
heaths commented 4 years ago

Using the Developer Command Prompt is what we recommend for setting up an environment. CMake also uses the VS setup query API to set variables for use in CMake (as do some other build toolsets), but please see their documentation for details. As for creating your own environment, you're welcome to look through vcvarsall.bat and related scripts, but note this is unsupported.