Visual Studio 2019 年的工具版本

ToolsVersion in Visual Studio 2019

我正在将几个项目从 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>

Project file contains ToolsVersion="16.5". This toolset may be unknown or missing

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

建议

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-->Current, VS2017-->15.0,VS2015-->14.0

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

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

这意味着它不能指定非法的工具版本16.5

解决方案

1) 前面说了把Realproject.vcxproj.

中的toolversion改成Current

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

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

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