Updated for Visual Studio 2017, 2019, and 2022
You can make this work actually, with just a few changes, if you only use the Visual Studio IDE itself (not MSBuild on the command line) to compile, with more or less full functionality on both platforms.
Unfortunately, the rules for C++ projects are different than C#/.NET, and require some manual intervention, unlike the C# projects fairly automatic for round tripping after project "upgrade". These changes will require editing the project files manually.
Later versions of Visual Studio will override the tools version when the build is run through the IDE. Simply setting the ToolsVersion
to 4.0, to satisfy Visual Studio 2010 and then fixing the PlatformToolset
in a common property group to get the correct default action in the Visual Studio 2015 IDE will probably do it.
The reason for setting PlatformToolset
is so that the defaults for correctly when changing build properties, like when you go to Debug
or Release
settings in the IDE and choose <inherit from parent or project defaults>
you will get the 2015 version by default and not 2010.
Steps for C++ project file cohabitation with Visual Studio 2010, 2015, 2017, 2019, and 2022:
- ToolsVersion attribute to 4.0
- Add common default value of PlatformToolset to v140 for Visual Studio 2015
- Add common default value of PlatformToolset to v141 for Visual Studio 2017
- Add common default value of PlatformToolset to v142 for Visual Studio 2019
- Add common default value of PlatformToolset to v143 for Visual Studio 2022
- Save file and reload project
1. Tools version to 4.0:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
...
By changing only 14.0
to 4.0
in Project
tag for ToolsVersion
it becomes
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
...
2. Add common default value of PlatformToolset to v140 recognized only by Visual Studio 2015:
<PropertyGroup Label="Globals">
<ProjectGuid>{12345678-9876-ABCD-DCCA-765FE987AA1F}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>myProject</RootNamespace>
<TargetPlatformVersion>8.1</TargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
By adding only the new PlatformToolset
line to the bottom of the PropertyGroup
it becomes:
<PropertyGroup Label="Globals">
<ProjectGuid>{12345678-9876-ABCD-DCCA-765FE987AA1F}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>myProject</RootNamespace>
<TargetPlatformVersion>8.1</TargetPlatformVersion>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '14.0'">v140</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '15.0'">v141</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '16.0'">v142</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '17.0'">v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
To also load in Visual Studio 2017, a line with toolset v141
is additional required as shown above to continue to seamlessly cross load projects between all three.
In Visual Studio 2019, a line with toolset v142
is additional required as shown above to continue to seamlessly cross load projects between all four.