将 SDK 与 Windows 10 更新同步并将 WinRT 与标准 C++ 结合使用

synchronizing SDK with Windows 10 update and using WinRT with Standard C++

我已经开始使用 Visual Studio 2017 Community Edition 试验 C++/WinRT。我现在有一个环境,我可以在其中构建示例应用程序的调试版本并 运行 它。我必须:

文档和网页描述了 Visual Studio 的 C++/WinRT 包更新,尝试编译该示例时出现错误,指示下载并安装最新的 Windows 10 SDK。

当我尝试 运行 示例应用程序的调试版本时,我发现我还需要 Windows 10 Build 1803。

Windows10 Build 1803 是运行使用 Stadard C++ 和 C++/WinRT 应用程序的要求,还是我的经验是由于使用调试版本?

这是否意味着没有将 Windows 10 安装升级到至少 Windows 10 Build 1803 的人将无法 运行 使用 C++/WinRT 开发的应用程序?

当企业或商业客户使用他们自己的特定更新集从他们自己的服务器进行企业特定升级时,是否有可能选择消除必要的 C++/WinRT 组件,以便 C++/WinRT 应用程序将在他们的环境中无法 运行?

是否有某种打包方式可以将必要的 C++/WinRT 组件包含在应用程序中?

附录:两个测试应用程序

我已经从头开始重试了我使用过的两个测试应用程序。这次重试是在安装最新的 Windows 10 SDK、10.0.17134、安装 C++/WinRT Visual Studio 扩展并将我的电脑更新到 Windows 10 1803 之后进行的修改。

我尝试的第一个 C++/WinRT 应用程序是来自 Kenny Kerr C++ - Introducing C++/WinRT 文章的控制台应用程序,它有以下示例应用程序:

#pragma comment(lib, "windowsapp")
#include "winrt/Windows.Foundation.h"
#include "winrt/Windows.Web.Syndication.h"
using namespace winrt;
using namespace Windows::Foundation;
using namespace Windows::Web::Syndication;
int main()
{
  initialize();        // NOTE: Generates compiler error C3861: 'initialize': identifier not found
  Uri uri(L"http://kennykerr.ca/feed");
  SyndicationClient client;
  SyndicationFeed feed = client.RetrieveFeedAsync(uri).get();
  for (SyndicationItem item : feed.Items())
  {
    hstring title = item.Title().Text();
    printf("%ls\n", title.c_str());
  }
}

我终于梳理出一个创建、编译和运行宁这个测试源的过程如下。从打开 Visual Studio 2017 Community Edition 开始,我做了以下操作:

"Configuration Properties" -> "General" 中的 "Windows SDK Version" 设置为 10.0.17134.0.

构建失败,编译错误 error C3861: 'initialize': identifier not found。进一步搜索发现这篇文章 cppwinrt.exe in the Windows SDK,其中包含一个使用 init_apartment(); 而不是 initialize(); 的示例应用程序,因此通过该更改我的示例应用程序编译并 运行s 生成列表文章作为输出。

这篇 Microsoft 文档文章 Get started with C++/WinRT,日期为 05/07/2018,其中有一个使用 init_apartment(); 而不是 initialize() 的控制台示例。该示例也是联合供稿,但不同 URL.

第二个测试应用程序使用了 "Windows Universal" -> "Blank App (C++/WinRT)" 的 C++/WinRT 模板,它生成了一个示例应用程序,它编译并 运行。在 "Properties" -> "General" 对话框中,"Target Platform Version" 设置为 10.0.17134.0,"Target Platform Minimum" 设置为 10.0.15063.0。

C++/WinRT 投影只是 C++ headers。除了您正在使用的 Windows 运行时 API 之外,它们本身没有特定的运行时要求。

真正的问题是您在应用程序中使用了哪些 API(通过 C++/WinRT 或使用 C++/CX 语言扩展 (a.k.a。/ZW)),以及您认为什么值已在构建 UWP 应用程序时设置为 WindowsTargetPlatformMinVersion 值。

WindowsTargetPlatformVersion 设置为最新的 Windows 10 SDK (17134),您可以将 UWP 应用所需的最低 OS 版本设置为 17134、16299、15063、14393 、10586 或 10240。您需要在该版本上测试您的应用程序,并确保防止使用更新的 API。

From a practical standpoint, you should not need to support 10240 which is why the default in Visual Studio for a new project is 10586. For consumer editions, 14393 is as old as you are ever likely to encounter in the real-world.