无法在 Visual Studio C++ 项目中更改 Windows SDK 版本

2022-01-12 00:00:00 visual-studio visual-studio-2017 c++

我有一个使用 Visual Studio 2015 创建的 Visual Studio C++ 控制台应用程序,但现在我无法编译它(使用 Visual Studio 2017),因为它针对的是未安装的 Windows 8.1 SDK.问题是我无法将项目重新定位到 Windows 10 SDK.

I have a Visual Studio C++ console application that I created with Visual Studio 2015 and now I can't compile it (with Visual Studio 2017) because it is targeting the Windows 8.1 SDK, which is not installed. The problem is that I can't retarget the project to the Windows 10 SDK.

发生的情况是,当我打开项目属性页面并转到 General - Target Platform 时,我在下拉列表中看到了 Windows 10 SDK,并且我可以选择它...但是作为一旦我按下 Apply,它会自行恢复到 8.1.没有提供错误消息.

What happens is that when I open the project properties page and go to General - Target Platform I see the Windows 10 SDK in the dropdown, and I am able to select it... but as soon as I press Apply, it reverts back to 8.1 by itself. No error message is provided.

Visual Studio 安装程序说,确实安装了列出的 SDK 版本:

Visual Studio installer says that, indeed, the listed SDK version is installed:

那么这里发生了什么?有没有办法重新定位我的项目而无需安装 Windows 8.1 SDK?

So what's going on here? Is there a way to retarget my project without having to install the Windows 8.1 SDK?

不确定这是否重要,但是:这个项目实际上只是一个现有裸项目的包装器",其中包含一堆 .cpp 和 .h 文件,这些文件是由另一个人开发的.我真的不熟悉 C++ 开发.

推荐答案

在解决这个问题几个小时后,我偶然发现选择Project Properties/General,将Platform Toolset"更改为v141_xp(而不是 v141) 强制将 Windows SDK 版本降至 8.1 或 7.0.我不确定 Visual Studio 如何选择使用哪个 SDK.

After hours of struggling with this problem, I coincidentally discovered that selecting Project Properties/General, changing "Platform Toolset" to v141_xp (instead of v141) forcibly drops the Windows SDK Version to 8.1 or 7.0. I'm not sure how Visual Studio chooses which SDK to use.

您必须编辑 .vcxproj 并同时更改:

You must edit .vcxproj and change both:

<TargetPlatformVersion>10.0.17134.0</TargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>

相关文章