为什么本机C ++项目有TargetFrameworkVersion?

时间:2014-02-18 06:06:42

标签: c++ .net visual-studio

在Visual Studio(v100,v110)中,可以使用项目文件中的TargetFrameworkVersion元素指定项目所针对的.NET框架的版本。 (如果没有TargetFrameworkVersion元素,IDE只使用其默认的.NET版本。)然后使用指定的TargetFrameworkVersion选择将用于构建项目的(默认)工具链。

CLR和本机C ++项目都是如此。我觉得这很奇怪而且令人困惑。如果Visual Studio知道项目是本机项目,那为什么它关心TargetFrameworkVersion是什么?

2 个答案:

答案 0 :(得分:2)

嗯,实际上你必须要求负责创建MSBuild脚本的开发人员,因为原则上它并不是真正需要的,也不是用的。他们自己也知道。对于标准C ++项目文件,这些是导致属性设置的行(Microsoft.Common.targets):

  <!-- By default, we are creating a managed app because .NET 2.0 projects did not have this property. -->
  <PropertyGroup Condition="'$(TargetRuntime)' == ''">
    <TargetRuntime>Managed</TargetRuntime>
  </PropertyGroup>

  <!-- Because .NET 2.0 apps did not set TargetFrameworkIdentifier, we need to set it for them here by default. If
       the runtime is set to Managed, we also need to set these.  Otherwise they should be blank (for instance Javascript or
       Native apps) because they do not target a .NET Framework. -->
  <PropertyGroup Condition="'$(TargetRuntime)' == 'Managed'">
    <TargetFrameworkIdentifier Condition="'$(TargetFrameworkIdentifier)' == ''">.NETFramework</TargetFrameworkIdentifier>
    <TargetFrameworkVersion Condition=" '$(TargetFrameworkVersion)' == '' ">v4.0</TargetFrameworkVersion>
  </PropertyGroup>

答案 1 :(得分:-1)

懒惰编程,基本上。 Microsoft历史上首选托管代码,因为它不能真正移植到其他操作系统,导致锁定。因此.NET语言在Visual Studio中具有更高的优先级。