Detect Visual Studio Version from MSBuild Project

The BuildingInsideVisualStudio property provides the ability to determine whether a project is being built inside Visual Studio.

Can I determine which version of Visual Studio is being used?

+7
source share
3 answers

Use the VisualStudioVersion property.

+6
source

Since the comments are not formatted, here a study showing fsimonazzi is correct. In 2008, VisualStudioVersion was NOT installed. In 2010 (and, presumably, presumably).

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 the output of VS2008 to Normal. Result:

 Target PrintVisualStudioInfo: VisualStudioVersion: '' 

In VS2010 Result:

 PrintVisualStudioInfo: VisualStudioVersion: '10.0' 
+6
source

According to this post, the property has existed since VS2012. It is defined in the Microsoft.Common.targets file when .NET 4.5 is installed (it is verified that the source .NET 4.0 does not have the specified property).

+5
source

All Articles