部署 WPF 应用程序Deploy a WPF Application

构建 Windows 演示基础 (WPF) 应用程序后,需要部署它们。After Windows Presentation Foundation (WPF) applications are built, they need to be deployed. Windows 和 .NET 框架包括多种部署技术。Windows and the .NET Framework include several deployment technologies. 用于部署 WPF 应用程序的部署技术取决于应用程序类型。The deployment technology that is used to deploy a WPF application depends on the application type. 本主题简要概述了每种部署技术,以及如何结合每种 WPF 应用程序类型的部署要求使用。This topic provides a brief overview of each deployment technology, and how they are used in conjunction with the deployment requirements of each WPF application type.

部署技术Deployment Technologies

Windows 和 .NET 框架包括多种部署技术,包括:Windows and the .NET Framework include several deployment technologies, including:

  • XCopy 部署。XCopy deployment.

  • Windows 安装程序部署。Windows Installer deployment.

  • ClickOnce 部署。ClickOnce deployment.

XCopy 部署XCopy Deployment

XCopy 部署是指使用 XCopy 命令行程序将文件从一个位置复制到另一个位置。XCopy deployment refers to the use of the XCopy command-line program to copy files from one location to another. XCopy 部署适用于下列情况:XCopy deployment is suitable under the following circumstances:

  • 应用程序是自包含的。The application is self-contained. 无需更新客户端,即可运行。It does not need to update the client to run.

  • 应用程序文件必须从一个位置移动到另一个位置,例如从生成位置(本地磁盘、UNC 文件共享等)移动到发布位置(网站、UNC 文件共享等)。Application files must be moved from one location to another, such as from a build location (local disk, UNC file share, and so on) to a publish location (Web site, UNC file share, and so on).

  • 应用程序无需进行 Shell 集成(“开始”菜单快捷方式、桌面图标等)。The application does not require shell integration (Start menu shortcut, desktop icon, and so on).

XCopy 适用于简单的部署方案;如果需要更为复杂的部署功能,则会限制使用 XCopy。Although XCopy is suitable for simple deployment scenarios, it is limited when more complex deployment capabilities are required. 具体而言就是,使用 XCopy 往往会导致创建、执行并维护能以可靠方式管理部署的脚本,并进而产生相应的开销。In particular, using XCopy often incurs the overhead for creating, executing, and maintaining scripts for managing deployment in a robust way. 此外,XCopy 不支持版本控制、卸载或回滚。Furthermore, XCopy does not support versioning, uninstallation, or rollback.

Windows InstallerWindows Installer

Windows 安装程序允许将应用程序打包为可独立执行文件,以便轻松分发到客户端并运行。Windows Installer allows applications to be packaged as self-contained executables that can be easily distributed to clients and run. 此外,Windows 安装程序与 Windows 一起安装,并启用与桌面、"开始"菜单和程序控制面板的集成。Furthermore, Windows Installer is installed with Windows and enables integration with the desktop, the Start menu, and the Programs control panel.

Windows 安装程序简化了应用程序的安装和卸载,但它不提供从版本控制的角度来看确保已安装的应用程序保持最新功能。Windows Installer simplifies the installation and uninstallation of applications, but it does not provide facilities for ensuring that installed applications are kept up-to-date from a versioning standpoint.

有关 Windows 安装程序的详细信息,请参阅Windows 安装程序部署For more information about Windows Installer, see Windows Installer Deployment.

ClickOnce 部署ClickOnce Deployment

ClickOnce 支持针对非 Web 应用程序部署 Web 样式的应用程序。ClickOnce enables Web-style application deployment for non-Web applications. 应用程序会发布到 Web 或文件服务器,也会从 Web 或文件服务器进行部署。Applications are published to and deployed from Web or file servers. 尽管 ClickOnce 不支持 Windows 安装程序安装的应用程序的全部客户端功能,但它确实支持包含以下内容的子集:Although ClickOnce does not support the full range of client features that Windows Installer-installed applications do, it does support a subset that includes the following:

  • 与“开始”菜单及“程序”控制面板集成。Integration with the Start menu and Programs control panel.

  • 版本控制、回滚和卸载。Versioning, rollback, and uninstallation.

  • 联机安装模式,该模式始终会从部署位置启动应用程序。Online install mode, which always launches an application from the deployment location.

  • 当有新版本发布时自动更新。Automatic updating when new versions are released.

  • 注册文件扩展名。Registration of file extensions.

有关单击"一次"的详细信息,请参阅单击"一次安全和部署"。For more information about ClickOnce, see ClickOnce Security and Deployment.

部署 WPF 应用程序Deploying WPF Applications

WPF 应用程序的部署选项取决于应用程序的类型。The deployment options for a WPF application depend on the type of application. 从部署的角度来看,WPF 有三种重要的应用程序类型:From a deployment perspective, WPF has three significant application types:

  • 独立应用程序。Standalone applications.

  • 仅标记 XAMLXAML 应用程序。Markup-only XAMLXAML applications.

  • XAML 浏览器应用程序 (XBAP)。XAML browser applications (XBAPs).

部署独立应用程序Deploying Standalone Applications

使用 ClickOnce 或 Windows 安装程序部署独立应用程序。Standalone applications are deployed using either ClickOnce or Windows Installer. 无论使用哪一项,独立应用程序都要在完全信任的状态下才能运行。Either way, standalone applications require full trust to run. 完全信任将自动授予使用 Windows 安装程序部署的独立应用程序。Full trust is automatically granted to standalone applications that are deployed using Windows Installer. 使用 ClickOnce 部署的独立应用程序不会自动授予完全信任。Standalone applications that are deployed using ClickOnce are not automatically granted full trust. 相反,ClickOnce 会显示用户在安装独立应用程序之前必须接受的安全警告对话框。Instead, ClickOnce displays a security warning dialog that users must accept before a standalone application is installed. 如果接受,独立应用程序就会安装并被授予完全信任状态。If accepted, the standalone application is installed and granted full trust. 如果不接受,则独立应用程序不会安装。If not, the standalone application is not installed.

部署仅标记 XAML 应用程序Deploying Markup-Only XAML Applications

XAMLXAML标记页面通常发布到 Web 服务器(如 HTML 页面),并且可以使用 Internet Explorer 查看。Markup-only XAMLXAML pages are usually published to Web servers, like HTML pages, and can be viewed using Internet Explorer. 仅标记 XAMLXAML 页面会按照 Internet 区域权限集定义的限制,在部分信任的安全沙箱内运行。Markup-only XAMLXAML pages run within a partial-trust security sandbox with restrictions that are defined by the Internet zone permission set. 这为基于 HTML 的 Web 应用程序提供了等效的安全沙盒。This provides an equivalent security sandbox to HTML-based Web applications.

有关 WPF 应用程序安全性的详细信息,请参阅安全For more information about security for WPF applications, see Security.

通过使用 XCopyXAMLXAML或 Windows 安装程序,只能将标记页面安装到本地文件系统。Markup-only XAMLXAML pages can be installed to the local file system by using either XCopy or Windows Installer. 可以使用 Internet 资源管理器或 Windows 资源管理器查看这些页面。These pages can be viewed using Internet Explorer or Windows Explorer.

有关 XAML 的详细信息,请参阅 XAML 概述 (WPF)For more information about XAML, see XAML Overview (WPF).

部署 XAML 浏览器应用程序Deploying XAML Browser Applications

XBAP 是需要部署以下三个文件的编译应用程序:XBAPs are compiled applications that require the following three files to be deployed:

  • 应用程序名称.exe:可执行的程序集应用程序文件。ApplicationName.exe: The executable assembly application file.

  • 应用程序名称.xbap:部署清单。ApplicationName.xbap: The deployment manifest.

  • 应用程序名称.exe.manifest:应用程序清单。ApplicationName.exe.manifest: The application manifest.

备注

有关部署和应用程序清单的详细信息,请参阅生成 WPF 应用程序For more information about deployment and application manifests, see Building a WPF Application.

这些文件是在生成 XBAP 时生成的。These files are produced when an XBAP is built. 有关详细信息,请参阅如何:创建新的 WPF 浏览器应用程序项目For more information, see How to: Create a New WPF Browser Application Project. 与仅XAMLXAML标记页面一样,XBAP 通常发布到 Web 服务器并使用 Internet 资源管理器进行查看。Like markup-only XAMLXAML pages, XBAPs are typically published to a Web server and viewed using Internet Explorer.

可以使用任何部署技术将 XBAP 部署到客户端。XBAPs can be deployed to clients using any of the deployment techniques. 但是,建议单击一次,因为它提供以下功能:However, ClickOnce is recommended since it provides the following capabilities:

  1. 当有新版本发布时自动更新。Automatic updates when a new version is published.

  2. 完全信任运行的 XBAP 的提升权限。Elevation privileges for the XBAP running with full trust.

默认情况下,ClickOnce 会使用.deploy 扩展名来发布应用程序文件。By default, ClickOnce publishes application files with the .deploy extension. 这可能会引发问题,但可被禁用。This can be problematic, but can be disabled. 有关详细信息,请参阅 ClickOnce 部署中的服务器和客户端配置问题For more information, see Server and Client Configuration Issues in ClickOnce Deployments.

有关部署 XAML 浏览器应用程序 (XBAPs) 的详细信息,请参阅WPF XAML 浏览器应用程序概述For more information about deploying XAML browser applications (XBAPs), see WPF XAML Browser Applications Overview.

安装 .NET FrameworkInstalling the .NET Framework

要运行 WPF 应用程序,必须在客户端上安装 Microsoft .NET 框架。To run a WPF application, the Microsoft .NET Framework must be installed on the client. 当查看 WPF 浏览器托管的应用程序时,Internet Explorer 会自动检测客户端是否安装了 .NET Framework。Internet Explorer automatically detects whether clients are installed with .NET Framework when WPF browser-hosted applications are viewed. 如果未安装 .NET 框架,Internet Explorer 会提示用户安装它。If the .NET Framework is not installed, Internet Explorer prompts users to install it.

为了检测是否安装了 .NET 框架,Internet Explorer 包括一个引导应用程序,该应用程序注册为具有以下扩展名的内容文件的回退多用途 Internet 邮件扩展 (MIME) 处理程序:.xaml、.xps、.xbap和 .应用程序。To detect whether the .NET Framework is installed, Internet Explorer includes a bootstrapper application that is registered as the fallback Multipurpose Internet Mail Extensions (MIME) handler for content files with the following extensions: .xaml, .xps, .xbap, and .application. 如果导航到这些文件类型,并且未在客户端上安装 .NET Framework,则引导程序应用程序将请求安装它的权限。If you navigate to these file types and the .NET Framework is not installed on the client, the bootstrapper application requests permission to install it. 如果未提供权限,则既不安装 .NET 框架,也不会安装应用程序。If permission is not provided, neither the .NET Framework nor the application is installed.

如果授予权限,Internet Explorer 将使用 Microsoft 后台智能传输服务 (BITS) 下载并安装 .NET 框架。If permission is granted, Internet Explorer downloads and installs the .NET Framework using the Microsoft Background Intelligent Transfer Service (BITS). 成功安装 .NET 框架后,在新的浏览器窗口中打开最初请求的文件。After successful installation of the .NET Framework, the originally requested file is opened in a new browser window.

有关详细信息,请参阅部署 .NET Framework 和应用程序For more information, see Deploying the .NET Framework and Applications.

另请参阅See also