title: Building Visual Studio 2015 C++ project (v140) by MSBuild Failed - v140 cannot be found
body: <p>I have Visual Studio 2013 and 2015 installed side by side. I have just upgraded the combined solution (C#, C++, C++/CLI) to 2015 and set Platform Toolset to v140.</p>
  
  <p>The build from Visual Studio works fine, but it cannot be compiled from MSBuild. I use MSBuild 14 and MSBuild complains that is unable to find v140, but it is nonsense, because v140 is installed on the computer in "c:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140".</p>
  
  <p>The advice about upgrading the solution cannot be done, because the solution is already upgraded and there is no such item in solution context menu.</p>
  
  <p>If I switch Platform tools of the project to v120, it works.</p>
  
  <p>Details:</p>
  
  <pre><code>c:\git\hewerMaster&gt;"c:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe"  c:\git
  \hewerMaster\Hewer.sln /property:Configuration=Debug /property:Platform=x86
  Microsoft (R) Build Engine version 14.0.23107.0
  Copyright (C) Microsoft Corporation. All rights reserved.
  
  Building the projects in this solution one at a time. To enable parallel build,
  please add the "/m" switch.
  Build started 9/12/2015 4:00:25 PM.
  Project "c:\git\hewerMaster\Hewer.sln" on node 1 (default targets).
  ValidateSolutionConfiguration:
    Building solution configuration "Debug|x86".
  ValidateProjects:
    The project "HewerDotNetWrapper" is not selected for building in solution con
    figuration "Debug|x86".
    The project "VisualHewer" is not selected for building in solution configurat
    ion "Debug|x86".
    The project "UnitTestWrapper" is not selected for building in solution config
    uration "Debug|x86".
    The project "ParamsFormatConverter" is not selected for building in solution
    configuration "Debug|x86".
    The project "UnitTestGenerator" is not selected for building in solution conf
    iguration "Debug|x86".
    The project "HewerUnitTestDotNet" is not selected for building in solution co
    nfiguration "Debug|x86".
  Project "c:\git\hewerMaster\Hewer.sln" (1) is building "c:\git\hewerMaster\Hewe
  rRedirect\HewerRedirect.csproj" (2) on node 1 (default targets).
  CoreCompile:
  Skipping target "CoreCompile" because all output files are up-to-date with resp
  ect to the input files.
  _CopyAppConfigFile:
  Skipping target "_CopyAppConfigFile" because all output files are up-to-date wi
  th respect to the input files.
  CopyFilesToOutputDirectory:
    HewerRedirect -&gt; c:\git\hewerMaster\anyCPU\Debug\pbrain-hewer.exe
  Done Building Project "c:\git\hewerMaster\HewerRedirect\HewerRedirect.csproj" (
  default targets).
  
  Project "c:\git\hewerMaster\Hewer.sln" (1) is building "c:\git\hewerMaster\Hewe
  r\Hewer.vcxproj" (3) on node 1 (default targets).
  C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.t
  argets(64,5): error MSB8020: The build tools for v140 (Platform Toolset = 'v140
  ') cannot be found. To build using the v140 build tools, please install v140 bu
  ild tools.  Alternatively, you may upgrade to the current Visual Studio tools b
  y selecting the Project menu or right-click the solution, and then selecting "U
  pgrade Solution...". [c:\git\hewerMaster\Hewer\Hewer.vcxproj]
  Done Building Project "c:\git\hewerMaster\Hewer\Hewer.vcxproj" (default targets
  ) -- FAILED.
  
  Done Building Project "c:\git\hewerMaster\Hewer.sln" (default targets) -- FAILE
  D.
  
  
  Build FAILED.
  </code></pre>
  
  <p>UPDATE:</p>
  
  <ul>
  <li>There are some project being skipped form Debug X86. This is intentional. </li>
  <li>The project have been originally created in VS2008, then upgraded to VS2013, then upgraded to VS2015.</li>
  <li>There are two Visual Studios installed on this computer (2013 Community and 2015 Community). 2013 was installed first, 2015 later.</li>
  </ul>
  
  <p>The registry settings looks like:
  <a href="https://i.stack.imgur.com/f0gSI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f0gSI.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/rGer3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rGer3.png" alt="MS Build registry settings"></a></p>
  
  <p><strong>UPDATE2:</strong>
  <a href="https://stackoverflow.com/help/mcve">Minimal, Complete, and Verifiable example</a></p>
  
  <p>I have created empty C++ Console Application in Visual Studio 2015:</p>
  
  <p><a href="https://dl.dropboxusercontent.com/u/53387801/ConsoleApplication_v140.zip" rel="nofollow noreferrer">https://dl.dropboxusercontent.com/u/53387801/ConsoleApplication_v140.zip</a></p>
  
  <pre><code>#include "stdafx.h"
  
  int main()
  {
      return 0;
  }
  </code></pre>
  
  <p>I can build it in Visual Studio, but I face the same issue in MSBuild:</p>
  
  <pre><code>c:\&gt;"c:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild" "C:\temp\vs2015_simplest\C
  onsoleApplication1\consoleApplication1.sln"
  Microsoft (R) Build Engine version 14.0.23107.0
  Copyright (C) Microsoft Corporation. All rights reserved.
  
  Building the projects in this solution one at a time. To enable parallel build,
  please add the "/m" switch.
  Build started 9/16/2015 10:16:20 AM.
  Project "C:\temp\vs2015_simplest\ConsoleApplication1\consoleApplication1.sln" o
  n node 1 (default targets).
  ValidateSolutionConfiguration:
    Building solution configuration "Debug|x64".
  Project "C:\temp\vs2015_simplest\ConsoleApplication1\consoleApplication1.sln" (
  1) is building "C:\temp\vs2015_simplest\ConsoleApplication1\ConsoleApplication1
  \ConsoleApplication1.vcxproj" (2) on node 1 (default targets).
  C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.t
  argets(64,5): error MSB8020: The build tools for v140 (Platform Toolset = 'v140
  ') cannot be found. To build using the v140 build tools, please install v140 bu
  ild tools.  Alternatively, you may upgrade to the current Visual Studio tools b
  y selecting the Project menu or right-click the solution, and then selecting "U
  pgrade Solution...". [C:\temp\vs2015_simplest\ConsoleApplication1\ConsoleApplic
  ation1\ConsoleApplication1.vcxproj]
  Done Building Project "C:\temp\vs2015_simplest\ConsoleApplication1\ConsoleAppli
  cation1\ConsoleApplication1.vcxproj" (default targets) -- FAILED.
  
  Done Building Project "C:\temp\vs2015_simplest\ConsoleApplication1\consoleAppli
  cation1.sln" (default targets) -- FAILED.
  
  
  Build FAILED.
  
  "C:\temp\vs2015_simplest\ConsoleApplication1\consoleApplication1.sln" (default
  target) (1) -&gt;
  "C:\temp\vs2015_simplest\ConsoleApplication1\ConsoleApplication1\ConsoleApplica
  tion1.vcxproj" (default target) (2) -&gt;
  (PlatformPrepareForBuild target) -&gt;
    C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform
  .targets(64,5): error MSB8020: The build tools for v140 (Platform Toolset = 'v1
  40') cannot be found. To build using the v140 build tools, please install v140
  build tools.  Alternatively, you may upgrade to the current Visual Studio tools
   by selecting the Project menu or right-click the solution, and then selecting
  "Upgrade Solution...". [C:\temp\vs2015_simplest\ConsoleApplication1\ConsoleAppl
  ication1\ConsoleApplication1.vcxproj]
  
      0 Warning(s)
      1 Error(s)
  
  Time Elapsed 00:00:00.14
  
  c:\&gt;
  </code></pre>
  
  <p><strong>SOLVED:</strong></p>
  
  <p><strong>Environment variable VisualStudioVersion was set to 12.0 instead of 14.0</strong> Changing the value to 14.0 solved the issue.</p>
  
  <p>The simple console application started to work immediately after the Environment variable VisualStudioVersion changed and after windows logout, login.</p>
  
  <p>The original project still couldn't be build after changing environment variable VisualStudioVersion. A retarget solution context menu appeared in Visual Studio 2015. So I retarget the solution. After retargeting the solution still couldn't be compiled (v140 not found). Finally I changed the platform toolset from <strong>v140 (not installed)</strong> to <strong>Visual Studio 2015 (v140)</strong>. Now the solution can be compiled from Visual Studio and MSBuild as well.</p>