Visual Studio 2019中的ToolsVersion

5

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

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

目标是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".

尽管构建已经成功,但我关心这个消息。这里可能出了什么问题?
更新: 提供项目结构的简化示例: 共同的 props:
<?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”会导致相同的消息... - Bogdan
当您尝试使用旧的4.0入口编译它时会发生什么? - magicandre1981
@magicandre1981,我在VS19下也收到了同样的4.0消息。 - Bogdan
将“4.0”替换为“Current”,并尝试是否有效。这是C++解决方案吗? - magicandre1981
@PerryQian-MSFT,抱歉耽搁了。是的,你说得对,完全删除ToolsVersion可以消除这个警告,同时不会影响编译。我想我会在所有项目中删除ToolsVersion。谢谢你的帮助。 - Bogdan
1个回答

8
项目文件包含ToolsVersion="16.5"。这个工具集可能未知或缺失。
要解决此问题,您应该进行一些更新。
建议:
1)右键单击VS2019 IDE上的项目->Retarget Projects,并将此项目定位到Windows 10 SDK版本并选择升级到v142。
2)在VS2019 IDE上右键单击您的项目->卸载项目->编辑(项目名称)。vcxproj->将ToolsVersion="4.0"更改为ToolsVersion="Current"->然后重新加载您的项目。
3)右键单击您的项目->属性->配置属性->常规->将平台工具集更改为Visual Studio 2019 v142。
----------------更新1-----------
首先,ToolVersion 与包含在 Visual Studio 版本中的 MSBuild 版本相关。一般来说,我们不会在 VS2019 中使用 16.5。请参见 this link。实际上,在 VS2019 中,ToolVersion 设置为 CurrentVS2019-->Current, VS2017-->15.0,VS2015-->14.0 您不能包含特定的小版本号。
这是我在我的测试中使用您的样例得出的结果,看起来只是一个警告:

enter image description here

这意味着它无法指定非法的工具版本16.5解决方案 1) 就像我之前说的那样,在Realproject.vcxproj中将toolversion更改为Current2) 删除Realproject.vcxproj中的toolversion xml节点,在VS2019中,它会自动识别工具版本而无需手动添加。
为了证明这一点,您可以创建一个新的VS2019 c ++项目,我确信您在xxxx.vcxproj文件中找不到toolversion节点。
然后尝试将我的解决方案应用于每个项目,我相信当您完成它时,该信息将不再出现。

我已经在props文件中定义了SDK和ToolSet:<PropertyGroup Label="Globals"> <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion></PropertyGroup> <PropertyGroup Label="Configuration"> <PlatformToolset>v142</PlatformToolset> </PropertyGroup>。不过,我还需要执行步骤1和3吗? - Bogdan
实际上,第一步和第三步与您所做的效果相同。您是否在xxx.vcxproj文件或Directory.Build.Props文件中定义了这样的节点?如果使用Directory.Build.Props,请更改为使用Directory.Build.targets文件。当您更改为使用“Current”时,是否遇到相同的问题?或者,您可以与我们分享其中一个xxx.vsxproj,以便帮助我们更快地排除您的问题。 - Mr Qian
我已经提供了一个vcxproj文件的示例(请参见编辑后的问题)。谢谢。 - Bogdan
2
在VS2019中我没有看到任何被称为“Retarget Projects”的东西。你能发一张截图吗? - not2qubit

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接