I have a c++ project created in Visual Studio 2017 community edition and I have opened and "converted" it with Visual Studio 2019 community edition. The project folder contains:
Main.sln
Main/Main.vcxproj
Main/Main.vcxproj.filters
Main/Main.vcxproj.user
According to Winmerge, the conversion only affected two values within Main/Main.vcxproj:
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
...
<PlatformToolset>v141</PlatformToolset>
changed to
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
...
<PlatformToolset>v142</PlatformToolset>
Also, I would like to know:
Thanks!
Hopefully, this will help someone later.
MSBuild supports conditionals defined within the.vcxproj files that can key off of the available macros. I also found that values can be replaced by being set again further down in the file.
This example talks about checking and setting the VisualStudioVersion macro.
The solutions I found use the DefaultPlatformToolset macro, which is v141 for VS2017 and v142 for VS2019.
There are two ways that Main.vcxproj could use this in a conditional:
1) Use the Choose, When, and Otherwise tags around PropertyGroups containing the necessary values:
<Choose>
<When Condition="'$(DefaultPlatformToolset)'=='v141'">
<PropertyGroup Label="Globals">
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
</When>
<When Condition="'$(DefaultPlatformToolset)'=='v142'">
<PropertyGroup Label="Globals">
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup Label="Globals">
<WindowsTargetPlatformVersion>$(DefaultWindowsSDKVersion)</WindowsTargetPlatformVersion>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
</PropertyGroup>
</Otherwise>
</Choose>
2) Set the Conditional property of the PropertyGroups:
<PropertyGroup Label="Globals">
<WindowsTargetPlatformVersion>$(DefaultWindowsSDKVersion)</WindowsTargetPlatformVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(DefaultPlatformToolset)'=='v141'" Label="Globals">
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(DefaultPlatformToolset)'=='v142'" Label="Globals">
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
Another approach may be to use a.sln file per Visual Studio version and base conditionals on the $(SolutionFileName) macro.
<Choose>
<When Condition="'$(SolutionFileName)'=='Main_VS2017.sln'">
...
</When>
<When Condition="'$(SolutionFileName)'=='Main_VS2019.sln'">
...
</When>
</Choose>
I've used the solution from http://www.markusweimer.com/2016/03/14/visual-c++/ hust converted it to 2015 and 2019.
<!--
Switch the PlatformToolset based on the Visual Studio Version
-->
<PropertyGroup>
<!-- Assume Visual Studio 2015 / 14.0 as the default -->
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
</PropertyGroup>
<!-- Visual Studio 2019 (16.0) -->
<PropertyGroup Condition="'$(VisualStudioVersion)' == '16.0'">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<!-- Visual Studio 2015 (14.0) -->
<PropertyGroup Condition="'$(VisualStudioVersion)' == '14.0'">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<!--
End of: Switch the PlatformToolset based on the Visual Studio Version
-->
Works like a charm...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.