如何在Visual Studio的C++项目中指定“任何Windows SDK版本大于10.0”?

11

这里的开发人员安装了不同的SDK,我希望我的Visual Studio项目使用大于10.0的任何可用SDK,而无需指定具体哪一个。有没有办法做到这一点?

enter image description here

在vcxproj文件中:

<WindowsTargetPlatformVersion>10.0.10586.0</WindowsTargetPlatformVersion>
2个回答

15

对于Visual Studio 2017,您必须在vcxproj文件中使用特定的SDK版本号。但是,在此帖子的评论中,Antonio Sanchez提供了Windows 10 SDK的解决方法:https://developercommunity.visualstudio.com/comments/190992/view.html

<PropertyGroup Condition="'$(WindowsTargetPlatformVersion)'==''">
    <!-- Latest Target Version property -->
    <LatestTargetPlatformVersion>
         $([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0'))
    </LatestTargetPlatformVersion>
    <WindowsTargetPlatformVersion Condition="'$(WindowsTargetPlatformVersion)' == ''">
        $(LatestTargetPlatformVersion)
    </WindowsTargetPlatformVersion>
    <TargetPlatformVersion>
        $(WindowsTargetPlatformVersion)
    </TargetPlatformVersion>
</PropertyGroup>

对于Visual Studio 2019,您可以使用10.0的值来指定Windows 10 SDK的最新版本。例如:

<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>

5
提示中的10.0很好,但当调用v140工具集时,它不适用于VS2019(16.5.3)-将显示以下错误:“...\PlatformToolsets\v140\Toolset.targets(34,5): error MSB8036: The Windows SDK version 10.0 was not found. ...” - AntonK
2
此外,工具集 v140 并不智能地剥离自动检测到的平台版本中的周围空格(换行符、制表符、空格等),因此您需要重写代码片段,以便每个 MSBuild 变量 与其值位于一行中。最终它按预期工作,这太棒了! :) - AntonK

3

当前的设计要求您的vcxproj包含特定的版本号。

由于您的项目是针对VS 2017(基于v141平台工具集)的,因此没有理由使用像15086这样旧的版本。如果有人今天安装了最新版的VS 2017(15.9更新),他们将默认拥有Windows 10 SDK(10.0.17763)。他们只有在安装了VS 2017(15.1更新)并且从未更新过它时,才会默认安装10.0.15806。

在vcxproj中坚持使用较旧的Windows 10 SDK只有在VS 2015项目中才有意义,因为10.0.14493是最后一个正式支持VS 2015的版本。

还要记住,对于Win32桌面应用程序,Windows 10 SDK(17763)仍然针对与Windows 10 SDK(15086)相同的Windows版本:Windows 7 SP1、Windows 8.x、Windows 10。


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