Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Visual Studio version from within MSBuild project

The BuildingInsideVisualStudio property provides the ability to detect whether a project is building inside Visual Studio.

Is there any way to determine which version of Visual Studio is being used ?

like image 472
WaffleSouffle Avatar asked Aug 13 '12 13:08

WaffleSouffle


1 Answers

Since comments aren't formatted, here's investigation showing fsimonazzi is correct. On 2008, VisualStudioVersion is NOT set. On 2010 (and up presumably) it is.

Created a project in VS2008 with the following added after <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />:

<Target Name="PrintVisualStudioInfo">
  <Message Text="VisualStudioVersion: '$(VisualStudioVersion)'" />
</Target>
<PropertyGroup>
  <CompileDependsOn>
    PrintVisualStudioInfo;
    $(CompileDependsOn)
  </CompileDependsOn>
</PropertyGroup>

Turned VS2008 output up to Normal. Result:

Target PrintVisualStudioInfo:
    VisualStudioVersion: ''

On VS2010 Result:

PrintVisualStudioInfo:
   VisualStudioVersion: '10.0'
like image 171
WaffleSouffle Avatar answered Oct 23 '22 10:10

WaffleSouffle