Thanks @zosrothko for the question. This is indeed a feature that is lacking in Gradle at the moment to choose the target compatibility which ends up being the tool chain that would result in been used.
I suggest having something like the following. Note that here the default is VS2017 but you could do a lightweight discovery to see if the installDir exists in the order you want to default to.
def getSelectedVisualStudioToolChain() {
String selector = System.properties["VS"]
if (selector == null) {
selector = "VS2017"
}
String installDir = null
switch (selector) {
case "VS2008": installDir = "file://C:/Program Files (x86)/Microsoft Visual Studio 9.0"; break;
case "VS2010": installDir = "file://C:/Program Files (x86)/Microsoft Visual Studio 10.0"; break;
case "VS2012": installDir = "file://C:/Program Files (x86)/Microsoft Visual Studio 11.0"; break;
case "VS2013": installDir = "file://C:/Program Files (x86)/Microsoft Visual Studio 12.0"; break;
case "VS2015": installDir = "file://C:/Program Files (x86)/Microsoft Visual Studio 14.0"; break;
case "VS2017": installDir = "file://C:/Program Files (x86)/Microsoft Visual Studio/2017/Community"; break;
default:
throw new IllegalArgumentException()
}
return [
name: selector,
installDir: installDir,
]
}
model {
toolChains {
def vsToolChain = getSelectedVisualStudioToolChain()
create(vsToolChain.name, VisualCpp) {
installDir vsToolChain.installDir
}
}
}
This use case is set to be solved with the new native plugins. Don’t hesitate to ask more question,