为什么本地C ++项目有一个TargetFrameworkVersion?有一个、项目、TargetFrameworkVersion

2023-09-05 03:33:51 作者:于心忍

在Visual Studio中(V100,V110),它可以指定使用TargetFrameworkVersion元素在项目文件中,一个项目的目标.NET Framework的版本。 (如果没有TargetFrameworkVersion的元素,IDE只使用其默认的.NET版本。)指定的TargetFrameworkVersion然后用于选择(默认),工具链将被用于建设该项目。

In Visual Studio (v100, v110) it is possible to specify the version of .NET framework that a project targets using the TargetFrameworkVersion element in the project file. (If there is no TargetFrameworkVersion element, the IDE just uses its default .NET version.) The specified TargetFrameworkVersion is then used to choose the (default) tool-chain which will be used to build the project.

以上是真的为CLR和本地C ++项目。我觉得这很奇怪和困惑。如果Visual Studio中知道一个项目是原生那么它为什么关心TargetFrameworkVersion是什么?

The above is true for both CLR and native C++ projects. I find this really weird and confusing. If Visual Studio knows a project is native then why does it care what the TargetFrameworkVersion is?

推荐答案

嗯,其实你要问负责创建的的MSBuild 脚本,因为在原则上是不是真的需要,也没用过。而他们自己也知道。对于一个标准的C ++项目文件,这些都是造成属性来获取设置线(Microsoft.Common.targets):

Well, actually you'd have to ask the developers responsible for creating the MSBuild scripts, because in principle it is not really needed, nor used. And they know it themselves. For a standard C++ project file, these are the lines causing the property to get set (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>