在 Visual Studio 中设置用于 MSIX 打包的桌面应用程序Set up your desktop application for MSIX packaging in Visual Studio

你可以使用 Visual Studio 中的 Windows 应用程序打包项目项目为桌面应用生成程序包。You can use the Windows Application Packaging Project project in Visual Studio to generate a package for your desktop app. 然后,可以将你的程序包分发到 Microsoft Store、Web、你的企业或你所使用的任何其他分发机制中。Then you can distribute your package to the Microsoft Store, on the Web, in your enterprise or any other distribution mechanism you're using.

必需的 Visual Studio 版本和工作负载Required Visual Studio version and workload

以下 Visual Studio 版本中提供了“Windows 应用程序打包项目”项目 :The Windows Application Packaging Project project is available in the following versions of Visual Studio:

  • Visual Studio 2019Visual Studio 2019
  • Visual Studio 2017 15.5 和更高版本Visual Studio 2017 15.5 and later

若要在“添加新项目”菜单中看到“Windows 应用程序打包项目”模板,需要确保至少安装了以下 Visual Studio 工作负载之一 :To see the Windows Application Packaging Project template in the 'Add New Project' menu, you need to make sure you have at least one of the following the Visual Studio workloads installed:

  • “通用 Windows 平台开发”工作负载The 'Universal Windows Platform development' workload
  • NET Core 工作负载中的可选组件“MSIX 打包工具”。The Optional Component 'MSIX Packaging Tools' in the NET Core workload.
  • .NET 桌面开发工作负载中的可选组件“MSIX 打包工具”。The Optional Component 'MSIX Packaging Tools' in the .NET desktop development workload.

为了获得最佳体验,建议使用最新 Visual Studio 版本。For the best experience we recommend that you use the latest Visual Studio release.

重要

Visual Studio 中的 Windows 应用程序打包项目项目在 Windows 10 版本 1607 和更高版本中受支持。The Windows Application Packaging Project project in Visual Studio is supported on Windows 10, version 1607, and later. 它只能用于面向 Windows 10 周年更新(10.0;内部版本 14393)或更高版本的项目中。It can only be used in projects that target Windows 10 Anniversary Update (10.0; Build 14393) or a later release.

下面是你可以从 Visual Studio 应用程序打包项目中执行的一些其他操作:Here are a few other things you can do from the Visual Studio Application Packaging Project:

✔️自动生成可视资产。Automatically generate visual assets.

✔️使用可视设计器对清单进行更改。Make changes to your manifest using a visual designer.

✔️使用向导生成程序包或捆绑包。Generate your package or bundle using a wizard.

✔️(如果发布到 Microsoft Store)基于你已在合作伙伴中心中预留的名称轻松为应用程序分配标识。(If publishing to the Microsoft Store) Easily assign an identity to your application from a name that you've already reserved in Partner Center.

准备应用程序Prepare your application

在开始为应用程序创建程序包之前请查看此指南:准备打包桌面应用程序Review this guide before you begin creating a package for your application: Prepare to package a desktop application.

在你的解决方案中设置 Windows 应用程序打包项目Setup the Windows Application Packaging Project in your solution

  1. 在 Visual Studio 中,打开包含你的桌面应用程序项目的解决方案。In Visual Studio, open the solution that contains your desktop application project.

  2. 向解决方案中添加一个 Windows 应用程序打包项目项目。Add a Windows Application Packaging Project project to your solution.

    你无需向此项目中添加任何代码。You won't have to add any code to it. 此项目只用于为你生成程序包。It's just there to generate a package for you. 我们将此项目称为“打包项目”。We'll refer to this project as the "packaging project".

    打包项目

  3. 将此项目的目标版本设置为你需要的任何版本,但请务必将最低版本设置为 Windows 10 周年更新Set the Target Version of this project to any version that you want, but make sure to set the Minimum Version to Windows 10 Anniversary Update.

    打包版本选择器对话框

  4. 在“解决方案资源管理器”中,右键单击打包项目下的“应用程序”文件夹,然后选择“添加引用”。 In Solution Explorer, right-click the Applications folder under the packaging project and choose Add Reference.

    添加项目引用

  5. 选择你的桌面应用程序项目,然后选择“确定” 按钮。Choose your desktop application project, and then choose the OK button.

    桌面项目

    你可以在程序包中包括多个桌面应用程序,但在用户选择应用磁贴时只能启动其中一个应用程序。You can include multiple desktop applications in your package, but only one of them can start when users choose your app tile. 在“应用程序” 节点中,右键单击你希望用户在选择应用磁贴时启动的应用程序,然后选择“设置为入口点” 。In the Applications node, right-click the application that you want users to start when they choose the app's tile, and then choose Set as Entry Point.

    设置入口点

  6. 生成打包项目,以确保未显示任何错误。Build the packaging project to ensure that no errors appear. 如果收到错误,请打开配置管理器并确保你的项目以同一平台为应用目标。If you receive errors, open Configuration Manager and ensure that your projects target the same platform.

    配置管理器

  7. 使用创建应用程序包向导生成 MSIX 程序包/捆绑包或 .msixupload/.appxupload 文件(用于发布到应用商店)。Use the Create App Packages wizard to generate an MSIX package/bundle or an .msixupload/.appxupload file (for Store publishing to the Store).

后续步骤Next steps

在 Visual Studio 中打包桌面应用Package your desktop app in Visual Studio

请参阅在 Visual Studio 中打包桌面或 UWP 应用See Package a Desktop or UWP app in Visual Studio

运行、调试或测试桌面应用程序Run, debug or test your desktop application

请参阅运行、调试和测试打包的应用程序See Run, debug, and test a packaged application

其他资源Additional resources

视频Video

 

通过添加 UWP API 来增强桌面应用程序Enhance your desktop application by adding UWP APIs

请参阅增强用于 Windows 10 的桌面应用程序See Enhance your desktop application for Windows 10

通过添加 UWP 项目和 Windows 运行时组件来扩展你的桌面应用程序Extend your desktop application by adding UWP projects and Windows Runtime Components

请参阅使用新式 UWP 组件扩展桌面应用程序See Extend your desktop application with modern UWP components.

分发你的应用Distribute your app

请参阅分发打包的桌面应用程序See Distribute a packaged desktop application