I solved this by writing a Visual Studio extension that temporarily sets the environment variable MSBUILDDEFAULTTOOLSVERSION
for the duration of a build; the value to be used is read from a file .toolsversion
in the same directory as the .sln
file. The psake script reads the same .toolsversion
file and passes the value to the /tv
switch.
The code for the extension can be found here: https://github.com/guyboltonking/set-toolsversion-extension. Sadly, I’m not working with C++, or indeed with Visual Studio, at the moment, so I can’t provide any support for it (but I can tell you I used it with no issues at all for several months).
Kudos to @efaruk for reminding me about the existence of MSBUILDDEFAULTTOOLSVERSION
.
Edit: Thanks to @mbadawi23, it’s now possible to use the extension with both VS2015 and VS2017.