步骤 1:创建 UWP 设备应用

Important

设备元数据已弃用,并将在 Windows 的将来版本中删除。 有关替代功能的信息,请参阅驱动程序包容器元数据

设备应用工作流,步骤 1。

本主题介绍使用 Microsoft Visual Studio 创建 UWP 设备应用的基本过程。 了解所有 UWP 设备应用通用的任务。

UWP 设备应用是一种特殊的 UWP 应用,设备制造商创建它作为其内部或外围设备的配套。 通过使用设备元数据,设备应用可以执行特权操作,并在设备插入时自动进行安装。 有关 UWP 设备应用的详细信息,请参阅 “满足 UWP 设备应用”。

本主题是分步系列的一部分。 请参阅 “逐步构建 UWP 设备应用” 以了解简介。

在您开始之前

本分步指南假定你已创建 UWP 应用项目,并且已存在任何必要的设备驱动程序。

创建 Microsoft 应用商店应用项目

在开始之前,需要安装 Visual Studio 并创建 UWP 应用项目。 如果尚未执行此作,可以 在此处下载工具。 若要开始使用 Microsoft Visual Studio,请参阅 使用 Visual Studio 开发 UWP 应用

设备驱动程序要求

某些 UWP 设备应用和 API 要求设备支持Microsoft提供的驱动程序或驱动程序支持特定的驱动程序模型。 下表列出了某些设备应用和 API 的驱动程序要求。

设备应用或 API Driver information
适用于相机的 UWP 设备应用 相机的驱动程序必须使用 AvStream 驱动程序模型。 For more information on the AvStream driver model, see the AVStream Overview in the Windows Driver Kit. 可以使用驱动程序安装包提供一个称为驱动程序 MFT(媒体基础转换)的其他组件,以提供相机的自定义效果。 有关详细信息,请参阅 适用于相机的 Windows 应用商店设备应用
适用于打印机的 UWP 设备应用 打印机必须使用 v4 打印机驱动程序。 有关详细信息 ,请参阅开发 v4 打印驱动程序
USB APIs To use the Windows RuntimeWindows.Devices.UsbAPIs, your device must be compatible with the Winusb.sys driver.
人机接口设备 (HID) API HID API 旨在通过 USB、蓝牙、蓝牙智能和 I2C 传输使用。 To use the Windows RuntimeWindows.Devices.HumanInterfaceDevice APIs, your device must be compatible with the HIDClass.sys driver and the driver required by the transport. For more info, see HID Architecture.
蓝牙 GATT API To use the Windows Runtime Bluetooth GATT APIs, Windows.Devices.Bluetooth.GenericAttributeProfile, your device must be compatible with the BthLEEnum.sys driver.
蓝牙 RFCOMM API To use the Windows Runtime Bluetooth RFCOMM APIs, Windows.Devices.Bluetooth.Rfcomm, your device must be compatible with the Rfcomm.sys and BthEnum.sys drivers.

Important

使用自定义驱动程序的设备访问需要Microsoft批准。 想要使用自定义驱动程序为专用设备实现设备访问的 OEM 和 IHV 应首先联系其Microsoft联系人,以便与 Windows 生态系统团队讨论其方案。 有关详细信息,请参阅 UWP 设备应用设计指南中针对电脑内部专用设备的自定义驱动程序访问模型部分。

创建 Microsoft Store 帐户

Microsoft Store 上的开发人员帐户是必需的。 在后续步骤中创作应用清单和设备元数据时,将需要发布者名称。 创建应用商店配置文件后,还可以为应用保留名称。

若要创建Microsoft应用商店帐户,请转到 Windows 开发人员中心

输入 发布者显示名称时,请输入应用应在Microsoft应用商店中列出的名称。 在帐户验证完成之前,将无法更改此名称。 仔细选择该名称,因为客户在浏览时会看到此名称,并会通过此名称了解你的应用。

将应用与 Microsoft 应用商店相关联

创建Microsoft应用商店帐户并选择发布者名称后,请将应用与 Microsoft 应用商店相关联。 Doing so will automatically download the following values to your local app package manifest file, named Package.appxmanifest.

  • 包显示名称

  • Package name

  • Publisher ID

  • 发布者显示名称

如果已开发设备元数据,则将应用与 Microsoft 应用商店相关联后,需要使用应用清单中的值更新设备元数据。

将应用与 Microsoft 应用商店相关联

  1. In Solution Explorer, right-click your project and then select Store > Associate App with the Store.

  2. 在“ 将应用与Microsoft应用商店 ”对话框关联中,单击“ 下一步”。 系统会提示你登录到 Microsoft 应用商店。

  3. On the Sign In page, sign in to the Microsoft Store and then click Next.

  4. 在此 包页的“选择应用名称 ”中,选择已保留 的应用名称 。 You can also click Reserve Name to go to the Microsoft Store to reserve one.

  5. After an app name is selected, click Next.

  6. 在摘要页上,查看所选的值。 If it looks good, click Associate. Otherwise, click Previous to go back and fix any errors. Clicking Associate automatically downloads the publisher display name and other values into the app package manifest.

查看应用包清单

将应用与 Microsoft Store 相关联后,请查看应用的程序包清单,查看发布者显示名称和其他值是否按预期插入。 确保应用标题和名称演示了与设备的强连接。 另请注意,应用包中只允许一个应用。

查看应用包清单

  1. In Solution Explorer, double-click the package.appxmanifest file. 这将打开清单设计器。 清单设计器是基础 XML 文件的图形 UI。

  2. After the file opens in Manifest Designer, click the Packaging tab to see the Package and Publisher information.

    To see the same information in XML, right-click package.appxmanifest and select Open With > XML (Text) Editor.

  3. 记下包名称、发布者名称和应用 ID。 下一步需要用到它们, 步骤 2:创建设备元数据

选择发布者证书

While you're reviewing the app package manifest with the Manifest Designer, choose a publisher certificate that matches the Publisher name in the manifest. While the Manifest Designer is open on the Packaging tab, click Choose Certificate to select the appropriate certificate.

开发 UWP 设备应用

开始开发 UWP 设备应用时,请考虑以下几点。

Device capabilities

若要访问设备,可能需要在应用包清单中指定设备功能。 These are specified with the DeviceCapability element of the Package.appxmanifest file in your app's project. 请注意,必须手动指定某些设备功能。 有关详细信息,请参阅 如何在包清单中指定设备功能

UWP 设备应用程序的自动播放功能

设备插入时,自动播放默认启动应用。 若要使用此功能,需要编辑应用包清单和设备元数据。 有关详细信息,请参阅 UWP 设备应用的自动播放

在后台同步或更新设备

可以使用设备后台任务从 UWP 设备应用同步或更新设备。 若要使用此功能,需要在设备元数据中将应用指定为特权应用。 有关详细信息,请参阅 UWP 设备应用的设备同步和更新

Learn more

使用 Windows 应用认证工具包

若要为应用提供获得认证的最佳机会,请在提交你的应用进行认证并列在 Microsoft 应用商店中之前,在计算机上安装并对其进行验证和测试。 有关详细信息,请参阅 Windows 应用认证工具包

Next step