Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a Visual Studio 2015 C++ project compatible with Visual Studio 2010?

My teacher is horsed to use Visual Studio 2010 by the school, because they don't want to bother installing anything new. I've been using Visual Studio 2015 and am really liking it. However, when she tries to run any of the code, it produces a bunch of errors. I tried a solution for making 2013/2012 projects compatible with 2010 by editing the solution file, but it still produces errors. Is there a solution?

Here is the console output when I try to run the source file in Visual Studio 2010:

1>------ Build started: Project: typingSalon, Configuration: Debug Win32 ------
1>Build started 4/8/2015 8:19:30 AM.
1>Project file contains ToolsVersion="14.0". This toolset is unknown or missing. You may be able to resolve this by installing the appropriate .NET Framework for this toolset. Treating the project as if it had ToolsVersion="4.0".
1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\Microsoft.Cpp.Win32.Targets(518,5): error MSB8008: Specified platform toolset (v140) is not installed or invalid. Please make sure that a supported PlatformToolset value is selected.
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.05
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
like image 358
Griffin Melson Avatar asked Apr 08 '15 13:04

Griffin Melson


1 Answers

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:

  1. ToolsVersion attribute to 4.0
  2. Add common default value of PlatformToolset to v140 for Visual Studio 2015
  3. Add common default value of PlatformToolset to v141 for Visual Studio 2017
  4. Add common default value of PlatformToolset to v142 for Visual Studio 2019
  5. Add common default value of PlatformToolset to v143 for Visual Studio 2022
  6. 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.

like image 141
Celess Avatar answered Sep 22 '22 18:09

Celess