Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to choose Visual Studio solution Platform Toolset for maximum compatibility

Background

I am open sourcing a few old Visual Studio applications I created a while back. I have created new solutions using my new VS2012 environment for them and have gotten the projects set up as git repositories. I got everything working fine in Visual Studio 2012 with no changes to the source code, all I needed to do was make sure I was linking the proper libraries in the new project configurations.

I would like to configure these projects as to have maximum compatibility for others downloading the project from Github. On this machine I have VS2010 installed alongside the latest VS2012 version. After I got everything working right for both of the projects in VS2012, I tried to open them up in VS2010.

When I tried to build I got a single error:

Specified platform toolset (v110) is not installed or invalid.
Please make sure that a supported PlatformToolset value is selected.    
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\Microsoft.Cpp.Win32.Targets  518

What I Tried

So I opened up the properties for the project, went to Configuration Options --> General and the Platform Toolset was indeed set to Visual Studio 2012 (v110). This input is a drop down box and the v110 value is not listed, instead I get two choices:

  • v100
  • v90

These correspond to VS2010 and VS2008 respectively. If I change the value to v100 and rebuild I get no errors and my program runs just fine in my Visual Studio 2010 environment.

When I open the project back up in Visual Studio 2012, if tells me that I have an old project file and asks if I want to upgrade, I say yes and it upgrades. I rebuild and run to make sure everything is still working. When I open the configuration options in VS2012 the Platform Toolset is set back to `Visual Studio 2012 (v110) but clicking the drop down input there are several more choices listed:

  • Visual Studio 2012 (v110)
  • v110_wp80
  • Visual Studio 2012 - Windows XP (v110_xp)
  • Visual Studio 2010 (v100)
  • Visual Studio 2008 (v90)
  • ‹inherit from parent or project defaults›

My Questions

This has led me to several questions. I am going to pose them all. It would be nice to get as much information as I can, but a good answer to just one of them would probably solve my problem.

  • If I'm not using features specific to newer versions of Visual Studio, is it possible to set up a solution which can be opened and run without modification in as many versions as possible (ie. 2008, 2010, or 2012)? If so, how?

  • If I set the Platform Toolset to v90 (VS2008) from within Visual Studio 2012, and it's able to build and run, does this mean that it will build and run for users with VS2012, VS2010, and VS2008?

  • What exactly does the <inherit for parent or project defaults> option do? What would the project defaults be set up as? Can this be used to tell Visual Studio to try to using whichever installed Platform Toolset will work.

  • Are there any other options besides Platform Toolset in Visual Studio that I can set to increase compatibility with others' development environments?

like image 678
Cory Gross Avatar asked Aug 07 '13 07:08

Cory Gross


People also ask

What is Platform toolset in Visual Studio?

The platform toolset consists of the C++ compiler (cl.exe) and linker (link.exe), along with the C/C++ standard libraries. Visual Studio 2015, Visual Studio 2017, and Visual Studio 2019 are binary-compatible. It's shown by the major version of the toolset, which has remained at 14.

How do I retarget a solution in Visual Studio?

Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution". To resolve these errors, right-click on the solution node in Solution Explorer and click Retarget solution.


1 Answers

This is a somewhat tricky situation. One of the underlying problems here is that VS2010 and VS2012 use MSBuild to build C++ projects, but VS2008 farmed it out to VCBuild instead. You can see this by comparing the project files. VS2010/VS2012 use .vcxproj, while VS2008 uses .vcproj.

If I'm not using features specific to newer versions of Visual Studio, is it possible to set up a solution which can be opened and run without modification in as many versions as possible (ie. 2008, 2010, or 2012)? If so, how?

For maximum compatibility, you want to target the lowest common denominator (i.e. vc90 in this case). Note that when you do the upgrade, the solution file and project files get upgraded to the latest version, which may break compatibility with older versions of Visual Studio.

If I set the Platform Toolset to v90 (VS2008) from within Visual Studio 2012, and it's able to build and run, does this mean that it will build and run for users with VS2012, VS2010, and VS2008?

Not really, due to the .vcxproj / .vcproj conflict stated above.

For example, I currently have a set of .vcxproj files and a solution designed for VS2010. I use VS2012 as my IDE, so when I open the VS2010 solution in VS2012, I choose to NOT upgrade it and simply open it as is. VS2012 and beyond should be backwards compatible back to VS2010 as far as project files go.

For maximum compatibility in development environments, my recommendation would be use VS2010's solution as the baseline, targeting v100. Developers can use any version newer than that and it should all work together gracefully.

like image 141
Soo Wei Tan Avatar answered Oct 24 '22 23:10

Soo Wei Tan