Detect Visual Studio version from within MSBuild project

我的梦境 提交于 2019-12-23 07:58:11

问题


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 ?


回答1:


Use the VisualStudioVersion property.




回答2:


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'



回答3:


According to this post the property exists starting with the VS2012. It is defined in the Microsoft.Common.targets file when .NET 4.5 is installed (checked that original .NET 4.0 doesn't have the property defined).



来源:https://stackoverflow.com/questions/11935426/detect-visual-studio-version-from-within-msbuild-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!