c# - ToolsVersion 和 TargetFrameworkVersion 之间的区别

标签 c# visual-studio-2012

ToolsVersionTargetFrameworkVersion 有什么区别?

<Project DefaultTargets="Build"  ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
   ......  
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>

最佳答案

区别在于 TargetFrameworkVersion 实际上有任何影响,而 ToolsVersion 通常完全完全忽略如果你使用的是 VS2013 以上的任何 VS,你的工具链。

正如 Daniel 简洁地指出的那样:

The target framework is for which .net framework features/classes are available to use in your code.


至于 ToolsVersion(在项目文件的 Project 元素内):

它会被忽略,除非您指定 MSBUILDLEGACYDEFAULTTOOLSVERSION:请注意 var 名称中的“legacy”。

这实际上在 MSDN 文档中得到了证明,但您必须在版本之间来回跳转并了解背景信息,例如 Compiling for ToolsVersion 12 with Visual Studio 2015也有帮助。

这里是相关的 MSDN 部分:(所有 emph。我的)

MSBuild Toolset (ToolsVersion)

When a ToolsVersion value is defined in a project file, MSBuild uses that value to determine the values of the Toolset properties that are available to the project. One Toolset property is $(MSBuildToolsPath), which specifies the path of the .NET Framework tools. Only that Toolset property (or $(MSBuildBinPath)), is required.

...这实际上是错误的,比较 VS2015 文档和 VS2012 文档,我们看到该段落被复制了下来。

但是,VS2015 文档继续第二段,VS2012 version 中缺少该段:

Starting in Visual Studio 2013, the MSBuild Toolset version is the same as the Visual Studio version number. MSBuild defaults to this Toolset within Visual Studio and on the command line, regardless of the toolset version specified in project file. This behavior can be overridden by using the /ToolsVersion flag. For more information, see Overriding ToolsVersion Settings.

在链接之后,我们看到:

Overriding ToolsVersion Settings

...

Order of Precedence

The order of precedence, from highest to lowest, used to determine the ToolsVersion is:

  1. The ToolsVersion attribute on the MSBuild task used to build the project, if any.
  2. The /toolsversion (or /tv) switch that's used in the msbuild.exe command, if any.
  3. If the environment variable MSBUILDTREATALLTOOLSVERSIONSASCURRENT is set, then use the current ToolsVersion.
  4. If the environment variable MSBUILDTREATHIGHERTOOLSVERSIONASCURRENT is set and the ToolsVersion defined in the project file is greater than the current ToolsVersion, use the current ToolsVersion.

  5. If the environment variable MSBUILDLEGACYDEFAULTTOOLSVERSION is set, or if ToolsVersion is not set, then the following steps are used:

    1. The ToolsVersion attribute of the Project element of the project file. If this attribute doesn’t exist, it is assumed to be the current version.
    2. The default tools version in the MSBuild.exe.config file.
    3. The default tools version in the registry. For more information, see Standard and Custom Toolset Configurations.
  6. If the environment variable MSBUILDLEGACYDEFAULTTOOLSVERSION is not set, then the following steps are used:

    1. If the environment variable MSBUILDDEFAULTTOOLSVERSION is set to a ToolsVersion that exists, use it.
    2. If DefaultOverrideToolsVersion is set in MSBuild.exe.config, use it.
    3. If DefaultOverrideToolsVersion is set in the registry, use it.
    4. Otherwise, use the current ToolsVersion.

请注意,项目文件仅在突出显示的情况下使用。

关于c# - ToolsVersion 和 TargetFrameworkVersion 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22943922/

相关文章:

c# - VS 2010 的键盘映射方案插件

c++ - 对于某些生成的项目,msbuild 将文件名解释为中文字符,而不是其他项目

.net - 针对同一 VS2012 项目中的 x86 和 x64 程序集;引用

c# - Crystal 报表: failed to open connection

c# - 创建具有哈希字符串支持的自定义 anchor 标记助手

c# - 如何在c#中使用对变量的引用

silverlight - Silverlight MVVM与NON-MVVM

visual-studio-2010 - Visual Studio 2013 在特定搜索关键字处有多个断点

c# - 在 C# 中将字符串转换为字节数组以在 C++ 中将字符串写入文件

c# - 应用程序尝试随机连接到互联网。为什么?