See the question and my original answer on StackOverflow

The problem, specific to the VS2012 with VS2010 combination, is described with details here: Visual Studio project compatibility and VisualStudioVersion

If you build a web project from the command line (not the developer prompt) then the value for VisualStudioVersion used will be 10.0. That is an artifact of the properties which I showed above. In this case you should pass this in as an MSBuild property. For example

msbuild.exe MyAwesomeWeb.csproj /p:VisualStudioVersion=11.0

In this case I’m passing in the property explicitly. This will always override any other mechanism to determine the value for VisualStudioVersion. If you are using the MSBuild task in a build script, then you can specify the property either in the Properties attribute or the AdditionalProperties attribute.

The post has a link to another post here: MSBuild: Properties and AdditionalProperties Known Metadata. This article explains this:

The difference is that if you specify properties using the Properties metadata then any properties defined using the Properties attribute on the MSBuild Task will be ignored. In contrast to that if you use the AdditionalProperties metadata then both values will be used, with a preference going to the AdditionalProperties values.

So one solution is to use the AdditionalProperties metadata that allow to define Properties late in the msbuild process, something like this:

<Project ToolsVersion="4.0" DefaultTargets="build" xmlns="">

    <CxxProjects Include="$(MSBuildThisFileDirectory)src\**\*.vcxproj">

  <Target Name="build">
    <MSBuild Projects="@(CxxProjects) />