【问题标题】:ToolsVersion in Visual Studio 2019Visual Studio 2019 中的工具版本
【发布时间】:2020-04-14 12:04:37
【问题描述】:

我正在将几个项目从 VS2010 迁移到 VS2019。这些项目的 vcxprojs 中有工具版本 4:

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

目标VS是VS2019 v16.5.0,MSBuild版本是16.5.0.12403,所以我尝试将ToolsVersion设置为16.5:

<Project DefaultTargets="Build" ToolsVersion="16.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

但似乎MSBuild不喜欢它:

1>Building with tools version "Current".
1>Project file contains ToolsVersion="16.5". This toolset may be unknown or missing, in which case you may be able to resolve this by installing the appropriate version of MSBuild, or the build may have been forced to a particular ToolsVersion for policy reasons. Treating the project as if it had ToolsVersion="Current".

尽管构建成功了,但我关心这个消息。这里有什么问题?

更新:
提供项目结构的简化示例:
常用道具:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
        <ShouldUnsetParentConfigurationAndPlatform>false</ShouldUnsetParentConfigurationAndPlatform>
</PropertyGroup>
<PropertyGroup Label="Globals">
        <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
        <DotNetFrameworkVersion>v4.0</DotNetFrameworkVersion>
</PropertyGroup>
<!-- Other common variables-->
</Project>

cpp 道具:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup Label="Configuration">
        <ConfigurationType>DynamicLibrary</ConfigurationType>
    </PropertyGroup>

    <PropertyGroup>
        <TargetExt>.dll</TargetExt>
    </PropertyGroup>

   <PropertyGroup Label="Configuration">
        <PlatformToolset>v142</PlatformToolset>
    </PropertyGroup>

    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    <Import Project="common.props" />

    <-- compiler, linker settings and so on -->
</Project>

实际项目:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="16.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup Label="Globals">
    <ProjectName>my_name</ProjectName>
    <ProjectGuid>{my_guid}</ProjectGuid>
    <RootNamespace>my_ns</RootNamespace>
    <Keyword>my_keyword</Keyword>
  </PropertyGroup>
  <Import Project="cpp.props" />
  <-- configurations (Release, Debug, x64/Win32 and so on -->
  <-- project-specific compiler/linker settings -->
  <-- items: cpp, heanders and so on -->
  <-- references -->
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>

【问题讨论】:

  • 顺便说一句,尝试设置“16.0”或“15.0”会导致相同的消息...
  • 当你尝试用旧的 4.0 条目编译它时会发生什么?
  • @magicandre1981,我在 VS19 下也收到了 4.0 的相同消息
  • 将“4.0”替换为“Current”并尝试是否可行。这是 C++ 解决方案吗?
  • @PerryQian-MSFT,抱歉耽搁了。是的,您是对的,完全删除 ToolsVersion 会删除此警告,同时不会破坏编译。我想我会在我的所有项目中删除 ToolsVersion。感谢您的帮助

标签: visual-studio-2010 msbuild visual-studio-2019


【解决方案1】:

项目文件包含 ToolsVersion="16.5"。此工具集可能未知 或失踪

要解决此问题,您应该进行一些更新。

建议

1),在VS2019 IDE上右键项目-->Retarget Projects,将此项目定位到Windows 10 SDK version,选择upgrade to v142

2),在VS2019 IDE上右键你的项目-->卸载项目-->编辑(项目名称).vcxproj-->把ToolsVersion="4.0"改成ToolsVersion="Current"-->然后重新加载你的项目

3) 右键单击​​您的项目-->属性-->配置属性-->常规-->将Platform Toolset更改为Visual Studio 2019 v142

----------------更新 1------------

首先,ToolVersion 与 Visual Studio 版本中包含的 MSBuild 版本有关。而且一般情况下,我们在 VS2019 中不使用16.5。见this link。实际上,在 VS2019 中,ToolVersion 设置为Current

VS2019--&gt;Current, VS2017--&gt;15.0,VS2015--&gt;14.0

您不能包含特定的小版本号。

这是我的测试结果,你的样本在我身边,看起来就像一个警告:

表示无法指定非法工具版本16.5

解决方案

1)正如我之前所说,将Realproject.vcxproj中的toolversion更改为Current

2)删除Realproject.vcxproj中的toolversion xml节点,VS2019会自动识别toolversion,无需手动添加。

为了证明这一点,你可以创建一个新的 VS2019 c++ 项目,我确信你在xxxx.vcxproj 文件中找不到 toolversion 节点。

然后在每个项目中尝试我的解决方案,我相信当你完成它时,信息不会再次出现。

【讨论】:

  • 我已经在 props 文件中定义了 SDK 和 ToolSet:&lt;PropertyGroup Label="Globals"&gt; &lt;WindowsTargetPlatformVersion&gt;10.0&lt;/WindowsTargetPlatformVersion&gt;&lt;/PropertyGroup&gt; &lt;PropertyGroup Label="Configuration"&gt; &lt;PlatformToolset&gt;v142&lt;/PlatformToolset&gt; &lt;/PropertyGroup&gt;。我还是应该执行第 1 步和第 3 步吗?
  • 其实第一步和第三步的效果和你做的一样。您是否在xxx.vcxproj 文件或Directory.Build.Props 文件中定义了此类嵌套?如果使用Directory.Build.Props,请改为使用Directory.Build.targets文件。当您更改为使用Current 时,会遇到同样的问题吗?或者您可以与我们分享xxx.vsxproj 之一,以便我们更快地解决您的问题。
  • 我提供了一个 vcxproj 文件的示例(请参阅已编辑的问题)。谢谢
猜你喜欢
  • 2020-09-14
  • 1970-01-01
  • 1970-01-01
  • 2019-09-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-12
  • 1970-01-01
相关资源
最近更新 更多