Wait, could it be you’re mixing the PlatformToolset
with VCTargetsVersion (e.g. _ToolsetVCTargetsVersion
) concept here?
PlatformToolset
: VS2013 (v120) , VS2015 (v140), VS2017 (v141), VS2019 (v142), VS2022 (v143)
VCTargetsVersion (from v170\Microsoft.Cpp.Default.props
):
<PropertyGroup>
<MinSupportedVCTargetsVersion Condition="'$(MinimumVisualStudioVersion)' == '17.0'">v170</MinSupportedVCTargetsVersion>
<MinSupportedVCTargetsVersion Condition="'$(MinimumVisualStudioVersion)' == '16.0'">v160</MinSupportedVCTargetsVersion>
<MinSupportedVCTargetsVersion Condition="'$(MinimumVisualStudioVersion)' == '15.0'">v150</MinSupportedVCTargetsVersion>
<MinSupportedVCTargetsVersion Condition="'$(MinimumVisualStudioVersion)' == '14.0'">v140</MinSupportedVCTargetsVersion>
<MinSupportedVCTargetsVersion Condition="'$(MinimumVisualStudioVersion)' == '12.0'">v120</MinSupportedVCTargetsVersion>
<MinSupportedVCTargetsVersion Condition="'$(MinimumVisualStudioVersion)' == '11.0'">v110</MinSupportedVCTargetsVersion>
</PropertyGroup>
And depending on those determined values one of the Microsoft.Cpp.Redirect.*.props
takes effect.
PlatformToolset
is what allowed you in newer VS versions — if installed — to use the v141_xp
platform toolset (i.e. actually compiler and tools from VS2017).
For the other glue rules for supported VCTargetsVersion it depends if the respective older VS is found when installing the newer one. For example my VS2022 on a machine with VS2019 has v160
and v170
rules, but lacks the rules vor v150
(except for one single Microsoft.Cpp.UnitTest.props
file which won’t even suffice to invoke a compiler — because VS2017 isn’t installed).
Practical example: on my system I have VS2019 and VS2022 currently installed. Now if I open the .sln
file which was created with VS2022 the Visual Studio Version Selector will determine my sample project is VS2022 and open that IDE. Now I go edit all instances of <PlatformToolset>v143</PlatformToolset>
to read <PlatformToolset>v142</PlatformToolset>
inside the project. Reopening the .sln
will still open the VS2022 IDE but this time I will be prompted to upgrade¹ but decline to do so.
Either way there is now a subtle difference in the Solution Explorer pane: the project shows the project name with (Visual Studio 2019)
appended. Provided the code can be built on VS2019, I can build from the VS2022 using the VS2019 compiler and tools on account of having that installed in parallel. Now let’s take it one further and change <PlatformToolset>v142</PlatformToolset>
to <PlatformToolset>v141</PlatformToolset>
, then reopening the .sln
. The VS2022 Solution Explorer shows the desired (Visual Studio 2017)
now.
But the Output pane shows the following:
warning : The build tools for Visual Studio 2017 (v141) cannot be found. To build using the Visual Studio 2022 (v143) build tools, either click the Project menu or right-click the solution, and then select “Retarget Solution”. Install Visual Studio 2017 (v141) to build using the Visual Studio 2017 (v141) build tools.
PS: @ben.boeckel I just installed VS2015 Pro (update 3) for giggles in a VM without any other VS version and I’m not sure if I simply misunderstand your statement, but it read to me as if you’re saying the VS2013 compiler was shipped with VS2015; which it wasn’t:
Note that the v120 toolchain is the VS2013 compiler, just shipped with the VS2015 IDE.
In that VM with VS2015 and without VS2013 I tried it. Changed it to <PlatformToolset>v120</PlatformToolset>
in a vanilla project I had created with the freshly installed VS2015 and I got:
warning : The build tools for Visual Studio 2013 (v120) cannot be found. To build using the Visual Studio 2015 (v140) build tools, either click the Project menu or right-click the solution, and then select “Upgrade Solution…”. Install Visual Studio 2013 (v120) to build using the Visual Studio 2013 (v120) build tools.
¹ Something I could suppress with <VCProjectUpgraderObjectName>NoUpgrade</VCProjectUpgraderObjectName>
in the global properties.