.NET Framework 部署指南(针对开发人员).NET Framework deployment guide for developers

本主题为想要随自己的应用一起安装任何 .NET Framework 版本(从 .NET Framework 4.5 到 .NET Framework 4.7.2.NET Framework 4.7.2 )的开发人员提供了相关信息。This topic provides information for developers who want to install any version of the .NET Framework from the .NET Framework 4.5 to the .NET Framework 4.7.2.NET Framework 4.7.2 with their apps.

有关下载链接,请参见可再发行组件包部分。For download links, see the section Redistributable Packages. 你还可从这些 Microsoft 下载中心页面下载可再发行组件包和语言包:You can also download the redistributable packages and language packs from these Microsoft Download Center pages:

重要说明:Important notes:

备注

短语“.NET Framework 4.5 及其单点版本”是指 .NET Framework 4.5 及所有更高版本。The phrase "the .NET Framework 4.5 and its point releases" refers to the .NET Framework 4.5 and all later versions.

  • 从 .NET Framework 4.5.1 到 .NET Framework 4.7.2.NET Framework 4.7.2 的 .NET Framework 版本是对 .NET Framework 4.5 的就地更新,这意味着它们将使用相同的运行时版本,但是程序集版本会进行更新,并且包括新类型和成员。Versions of the .NET Framework from the .NET Framework 4.5.1 through the .NET Framework 4.7.2.NET Framework 4.7.2 are in-place updates to the .NET Framework 4.5, which means they use the same runtime version, but the assembly versions are updated and include new types and members.

  • .NET Framework 4.5 及其单点版本以增量方式在 .NET Framework 4上创建。The .NET Framework 4.5 and its point releases are built incrementally on the .NET Framework 4. 在安装了 .NET Framework 4 的系统上安装 .NET Framework 4.5 或其单点版本时,版本 4 程序集将替换为更新版本。When you install the .NET Framework 4.5 or its point releases on a system that has the .NET Framework 4 installed, the version 4 assemblies are replaced with newer versions.

  • 如果你正在应用中引用一个 Microsoft 带外包 ,则程序集将包括在应用包内。If you are referencing a Microsoft out-of-band package in your app, the assembly will be included in the app package.

  • 你必须拥有管理员特权才能安装 .NET Framework 4.5 及其单点版本。You must have administrator privileges to install the .NET Framework 4.5 and its point releases.

  • .NET Framework 4.5 和 Windows 8Windows 8 中已经包括 Windows Server 2012Windows Server 2012,因此你不必在这些操作系统上随你的应用一起部署此组件。The .NET Framework 4.5 is included in Windows 8Windows 8 and Windows Server 2012Windows Server 2012, so you don't have to deploy it with your app on those operating systems. 同样, .NET Framework 4.5.1 和 Windows Server 2012 R2 中也已包括 Windows 8.1Windows 8.1Similarly, the .NET Framework 4.5.1 is included in Windows 8.1Windows 8.1 and Windows Server 2012 R2. .NET Framework 4.5.2 不包含在任何操作系统中。The .NET Framework 4.5.2 isn't included in any operating systems. .NET Framework 4.6 包括在 Windows 10 中, .NET Framework 4.6.1 包括在 Windows 10 十一月更新中,而 .NET Framework 4.6.2 包括在 Windows 10 周年更新中。The .NET Framework 4.6 is included in Windows 10, the .NET Framework 4.6.1 is included in Windows 10 November Update, and the .NET Framework 4.6.2 is included in Windows 10 Anniversary Update. .NET Framework 4.7 包含在 Windows 10 创意者更新中,.NET Framework 4.7.1 包含在 Windows 10 Fall Creators Update 中,.NET Framework 4.7.2 包含在 Windows 10 2018 年 10 月更新和 Windows 10 2018 年 4 月更新中。The .NET Framework 4.7 is included in Windows 10 Creators Update, the .NET Framework 4.7.1 is included in Windows 10 Fall Creators Update, and the .NET Framework 4.7.2 is included in Windows 10 October 2018 Update and Windows 10 April 2018 Update. 有关硬件和软件要求的完整列表,请参阅系统要求For a full list of hardware and software requirements, see System Requirements.

  • 从 .NET Framework 4.5开始,你的用户可以在安装过程中查看运行中 .NET Framework 应用的列表并轻松关闭这些应用。Starting with the .NET Framework 4.5, your users can view a list of running .NET Framework apps during setup and close them easily. 这可能有助于避免系统因安装 .NET Framework 而重新启动。This may help avoid system restarts caused by .NET Framework installations. 参见 减少系统重新启动See Reducing System Restarts.

  • 卸载 .NET Framework 4.5 或其单点版本之一也会删除预先存在的 .NET Framework 4 文件。Uninstalling the .NET Framework 4.5 or one of its point releases also removes pre-existing .NET Framework 4 files. 若要返回到 .NET Framework 4,你必须重新安装它以及它的任何更新。If you want to go back to the .NET Framework 4, you must reinstall it and any updates to it. (请参阅 安装 .NET Framework 4。)(See Installing the .NET Framework 4.)

  • .NET Framework 4.5 可再发行组件于 2012 年 10 月 9 日进行了更新,纠正了一个与数字证书中的错误时间戳相关的问题,此问题会导致 Microsoft 生成并签名的文件中的数字签名提前过期。The .NET Framework 4.5 redistributable was updated on October 9, 2012 to correct an issue related to an improper timestamp on a digital certificate, which caused the digital signature on files produced and signed by Microsoft to expire prematurely. 如果之前安装了日期为 2012 年 8 月 16 日的 .NET framework 4.5 可再发行组件包,则建议使用 Microsoft 下载中心中的最新的可再发行组件来更新副本。If you previously installed the .NET Framework 4.5 redistributable package dated August 16, 2012, we recommend that you update your copy with the latest redistributable from the Microsoft Download Center. 有关此问题的更多信息,请参阅 Microsoft 安全公告 2749655For more information about this issue, see Microsoft Security Advisory 2749655.

有关系统管理员可如何在网络中部署 .NET Framework 及其系统依赖项的信息,请参见阅适用于管理员的部署指南For information about how a system administrator can deploy the .NET Framework and its system dependencies across a network, see Deployment Guide for Administrators.

应用的部署选项Deployment options for your app

当准备好将你的应用发布到 Web 服务器或其他集中位置时,以便用户可以安装此应用时,你可以选择多种部署方法。When you're ready to publish your app to a web server or other centralized location so that users can install it, you can choose from several deployment methods. 其中一些随 Visual Studio 一起提供。Some of these are provided with Visual Studio. 下表列出了你的应用的部署选项,并指定了支持每个选项的 .NET Framework 可再发行组件包。The following table lists the deployment options for your app and specifies the .NET Framework redistributable package that supports each option. 除此之外,你还可以为你的应用编写自定义安装程序;有关更多信息,请参见 将 .NET Framework 安装链接到应用的安装程序一节。In addition to these, you can write a custom setup program for your app; for more information, see the section Chaining the .NET Framework Installation to Your App's Setup.

你的应用的部署策略Deployment strategy for your app 可用的部署方法Deployment methods available 要使用的 .NET Framework 可再发行组件.NET Framework redistributable to use
从 Web 安装Install from the web - InstallAware- InstallAware
- InstallShield- InstallShield
- WiX 工具集- WiX toolset
- 手动安装- Manual installation
Web installerWeb installer
从磁盘安装Install from disc - InstallAware- InstallAware
- InstallShield- InstallShield
- WiX 工具集- WiX toolset
- 手动安装- Manual installation
Offline installerOffline installer
从局域网安装(适用于企业应用)Install from a local area network (for enterprise apps) - ClickOnce- ClickOnce Web 安装程序 (有关限制,请参见 ClickOnce )或 脱机安装程序Either web installer (see ClickOnce for restrictions) or offline installer

可再发行组件包Redistributable Packages

.NET framework 通过两种可再发行组件包提供:Web 安装程序(引导程序)和脱机安装程序(独立的可再发行组件)。The .NET Framework is available in two redistributable packages: web installer (bootstrapper) and offline installer (stand-alone redistributable). 下表对两种组件包进行了比较。The following table compares the two packages.

Web 安装程序Web installer 脱机安装程序Offline installer
下载文件Download file .NET Framework 4.7.2:.NET Framework 4.7.2:
NDP472-KB4054531-Web.exeNDP472-KB4054531-Web.exe

.NET Framework 4.7.1:.NET Framework 4.7.1:
NDP471-KB4033344-Web.exeNDP471-KB4033344-Web.exe

.NET Framework 4.7:.NET Framework 4.7:
NDP47-KB3186500-Web.exeNDP47-KB3186500-Web.exe

.NET Framework 4.6.2:
NDP462-KB3151802-Web.exeNDP462-KB3151802-Web.exe

.NET Framework 4.6.1:
NDP461-KB3102438-Web.exeNDP461-KB3102438-Web.exe

.NET Framework 4.6:
NDP46-KB3045560-Web.exeNDP46-KB3045560-Web.exe

.NET Framework 4.5.2:.NET Framework 4.5.2:
NDP452-KB2901954-Web.exeNDP452-KB2901954-Web.exe

.NET Framework 4.5.1:
NDP451-KB2859818-Web.exeNDP451-KB2859818-Web.exe

.NET Framework 4.5:
dotNetFx45_Full_setup.exedotNetFx45_Full_setup.exe
.NET Framework 4.7.2:.NET Framework 4.7.2:
NDP472-KB4054530-x86-x64-AllOS-ENU.exeNDP472-KB4054530-x86-x64-AllOS-ENU.exe

.NET Framework 4.7.1:.NET Framework 4.7.1:
NDP471-KB4033342-x86-x64-AllOS-ENU.exeNDP471-KB4033342-x86-x64-AllOS-ENU.exe

.NET Framework 4.7:.NET Framework 4.7:
NDP47-KB3186497-x86-x64-AllOS-ENU.exeNDP47-KB3186497-x86-x64-AllOS-ENU.exe

.NET Framework 4.6.2:
NDP462-KB3151800-x86-x64-AllOS-ENU.exeNDP462-KB3151800-x86-x64-AllOS-ENU.exe

.NET Framework 4.6.1:
NDP461-KB3102436-x86-x64-AllOS-ENU.exeNDP461-KB3102436-x86-x64-AllOS-ENU.exe

.NET Framework 4.6:
NDP46-KB3045557-x86-x64-AllOS-ENU.exeNDP46-KB3045557-x86-x64-AllOS-ENU.exe

.NET Framework 4.5.2:.NET Framework 4.5.2:
NDP452-KB2901907-x86-x64-AllOS-ENU.exeNDP452-KB2901907-x86-x64-AllOS-ENU.exe

.NET Framework 4.5.1:
NDP451-KB2858728-x86-x64-AllOS-ENU.exeNDP451-KB2858728-x86-x64-AllOS-ENU.exe

.NET Framework 4.5:
dotNetFx45_Full_x86_x64.exedotNetFx45_Full_x86_x64.exe
是否需要 Internet 连接?Internet connection required? Yes NoNo
下载文件大小Size of download 较小(仅包含面向目标平台的安装程序)*Smaller (includes installer for target platform only)* 较大*Larger*
语言包Language packs 包括**Included** 除非使用面向所有操作系统的程序包,否则必须 单独安装Must be installed separately, unless you use the package that targets all operating systems
部署方法Deployment method 支持所有方法:Supports all methods:

- ClickOnce- ClickOnce
- InstallAware- InstallAware
- InstallShield- InstallShield
- Windows Installer XML (WiX)- Windows Installer XML (WiX)
- 手动安装- Manual installation
- 自定义安装(链接)- Custom setup (chaining)
支持所有方法:Supports all methods:

- ClickOnce- ClickOnce
- InstallAware- InstallAware
- InstallShield- InstallShield
- Windows Installer XML (WiX)- Windows Installer XML (WiX)
- 手动安装- Manual installation
- 自定义安装(链接)- Custom setup (chaining)
ClickOnce 部署的下载位置Location of download for ClickOnce deployment Microsoft 下载中心:Microsoft Download Center:

- .NET Framework 4.7.2- .NET Framework 4.7.2
- .NET Framework 4.7.1- .NET Framework 4.7.1
- .NET Framework 4.7- .NET Framework 4.7
- .NET Framework 4.6.2- .NET Framework 4.6.2
- .NET Framework 4.6.1- .NET Framework 4.6.1
- .NET Framework 4.6- .NET Framework 4.6
- .NET Framework 4.5.2- .NET Framework 4.5.2
- .NET Framework 4.5.1- .NET Framework 4.5.1
- .NET Framework 4.5- .NET Framework 4.5
你自己的服务器或 Microsoft 下载中心:Your own server or the Microsoft Download Center:

- .NET Framework 4.7.2- .NET Framework 4.7.2
- .NET Framework 4.7.1- .NET Framework 4.7.1
- .NET Framework 4.7- .NET Framework 4.7
- .NET Framework 4.6.2- .NET Framework 4.6.2
- .NET Framework 4.6.1- .NET Framework 4.6.1
- .NET Framework 4.6- .NET Framework 4.6
- .NET Framework 4.5.2- .NET Framework 4.5.2
- .NET Framework 4.5.1- .NET Framework 4.5.1
- .NET Framework 4.5- .NET Framework 4.5

* 因为脱机安装程序包含面向所有目标平台的组件,因此它更大。* The offline installer is larger because it contains the components for all the target platforms. 当运行完安装程序后,Windows 操作系统仅会缓存已用的安装程序。When you finish running setup, the Windows operating system caches only the installer that was used. 如果安装后删除脱机安装程序,则所使用的磁盘空间与 Web 安装程序使用的空间相同。If the offline installer is deleted after the installation, the disk space used is the same as that used by the web installer. 如果你用来创建应用安装程序的工具(例如,InstallAwareInstallShield)提供了一个会在安装后移除的安装文件文件夹,则将脱机安装程序放入此安装文件夹可自动删除该安装程序。If the tool you use (for example, InstallAware or InstallShield) to create your app's setup program provides a setup file folder that is removed after installation, the offline installer can be automatically deleted by placing it into the setup folder.

** 如果使用支持自定义安装的 Web 安装程序,则可以使用基于用户的多语言用户界面 (MUI) 的默认语言设置,或使用命令行上的 /LCID 选项指定其他语言包。** If you're using the web installer with custom setup, you can use default language settings based on the user's Multilingual User Interface (MUI) setting, or specify another language pack by using the /LCID option on the command line. 有关示例,请参见 使用默认 .NET Framework UI 进行链接 一节。See the section Chaining by Using the Default .NET Framework UI for examples.

部署方法Deployment methods

有四种部署方法可用:Four deployment methods are available:

  • 可以设置一个对 .NET Framework 的依赖项。You can set a dependency on the .NET Framework. 使用下列方法之一,你可以将 .NET Framework 指定为应用安装程序中的一个必备组件:You can specify the .NET Framework as a prerequisite in your app's installation, using one of these methods:

  • 你可以要求用户 手动安装 .NET FrameworkYou can ask your users to install the .NET Framework manually.

  • 你可以在应用的安装程序中链接(包括) .NET Framework 安装过程,并确定要如何处理 .NET Framework 安装体验:You can chain (include) the .NET Framework setup process in your app's setup, and decide how you want to handle the .NET Framework installation experience:

    • 使用默认 UIUse the default UI. 由 .NET Framework 安装程序提供安装体验。Let the .NET Framework installer provide the installation experience.

    • 自定义 UI 以提供一种统一安装体验并监视 .NET Framework 的安装进度。Customize the UI to present a unified installation experience and to monitor the .NET Framework installation progress.

以下各节将详细讨论这些部署方法。These deployment methods are discussed in detail in the following sections.

设置对 .NET Framework 的依赖项Setting a dependency on the .NET Framework

如果使用 ClickOnce、InstallAware、InstallShield 或 WiX 来部署你的应用,则可以添加一个对 .NET Framework 的依赖项,以便将其作为应用的一部分进行安装。If you use ClickOnce, InstallAware, InstallShield, or WiX to deploy your app, you can add a dependency on the .NET Framework so it can be installed as part of your app.

ClickOnce 部署ClickOnce deployment

ClickOnce 部署适用于使用 Visual Basic 和 Visual C# 创建的项目,但不适用于 Visual C++。ClickOnce deployment is available for projects that are created with Visual Basic and Visual C#, but it is not available for Visual C++.

在 Visual Studio 中,若要选择 ClickOnce 部署并添加对 .NET Framework 的依赖项:In Visual Studio, to choose ClickOnce deployment and add a dependency on the .NET Framework:

  1. 打开要发布的应用项目。Open the app project you want to publish.

  2. 在“解决方案资源管理器”中,打开项目的快捷菜单,然后选择 “属性”In Solution Explorer, open the shortcut menu for your project, and then choose Properties.

  3. 选择 “发布” 窗格。Choose the Publish pane.

  4. 选择 “系统必备” 按钮。Choose the Prerequisites button.

  5. “系统必备” 对话框中,确保选中 “创建用于安装系统必备组件的安装程序” 复选框。In the Prerequisites dialog box, make sure that the Create setup program to install prerequisite components check box is selected.

  6. 在必备组件列表中,找到并选择已用于生成项目的.NET Framework 版本。In the prerequisites list, locate and select the version of the .NET Framework that you've used to build your project.

  7. 选择一个选项以指定必备组件的源位置,然后选择 “确定”Choose an option to specify the source location for the prerequisites, and then choose OK.

    如果你提供 .NET Framework 下载位置的 URL,则可以指定 Microsoft 下载中心网站或你自己的网站。If you supply a URL for the .NET Framework download location, you can specify either the Microsoft Download Center site or a site of your own. 如果要将可再发行组件包放置在自己的服务器上,则它必须为脱机安装程序,而不是 Web 安装程序。If you are placing the redistributable package on your own server, it must be the offline installer and not the web installer. 你只能链接到 Microsoft 下载中心上的 Web 安装程序。You can only link to the web installer on the Microsoft Download Center. 该 URL 还可以指定一个用于分发你的应用的磁盘。The URL can also specify a disc on which your own app is being distributed.

  8. “属性页” 对话框中,选择 “确定”In the Property Pages dialog box, choose OK.

InstallAware 部署InstallAware deployment

InstallAware 从单个源生成 Windows 应用 (APPX)、Windows Installer (MSI)、本机代码 (EXE) 和 APP-V (Application Virtualization) 包。InstallAware builds Windows app (APPX), Windows Installer (MSI), Native Code (EXE), and App-V (Application Virtualization) packages from a single source. 可以通过编辑默认脚本自定义安装,轻松在你的安装程序中包括任何版本的 .NET FrameworkEasily include any version of the .NET Framework in your setup, optionally customizing the installation by editing the default scripts. 例如,InstallAware 会在 Windows 7 上预安装证书,否则 .NET Framework 4.7 安装程序将失败。For example, InstallAware pre-installs certificates on Windows 7, without which the .NET Framework 4.7 setup fails. 有关 InstallAware 的详细信息,请参阅面向 Windows Installer 的 InstallAware 网站。For more information on InstallAware, see the InstallAware for Windows Installer website.

InstallShield 部署InstallShield deployment

在 Visual Studio 中,若要选择 InstallShield 部署并添加对 .NET Framework 的依赖项:In Visual Studio, to choose InstallShield deployment and add a dependency on the .NET Framework:

  1. 在 Visual Studio 菜单栏上,依次选择 “文件”“新建”“项目”On the Visual Studio menu bar, choose File, New, Project.

  2. “新建项目” 对话框的左窗格中,依次选择 “其他项目类型”“安装和部署”“InstallShield LE”In the left pane of the New Project dialog box, choose Other Project Types, Setup and Deployment, InstallShield LE.

  3. “名称” 框中,键入你的项目名称,然后选择 “确定”In the Name box, type a name for your project, and then choose OK.

  4. 如果你是首次创建安装和部署项目,请选择“转到 InstallShield”或“启用 InstallShield Limited Edition”,以下载你的 Microsoft Visual Studio 版本对应的 InstallShield Limited Edition。If you are creating a setup and deployment project for the first time, choose Go to InstallShield or Enable InstallShield Limited Edition to download InstallShield Limited Edition for your version of Microsoft Visual Studio. 重新启动 Visual Studio。Restart Visual Studio.

  5. 转到 “项目助手” 向导,选择 “应用程序文件” 以添加项目输出。Go to Project Assistant wizard and choose Application Files to add the Project Output. 你可以使用此向导配置其他项目特性。You can configure other project attributes by using this wizard.

  6. 转到 “安装要求” ,选择要安装的操作系统和 .NET Framework 的版本。Go to Installation Requirements and select the operating systems and the version of the .NET Framework you want to install.

  7. 打开安装项目的快捷菜单,然后选择 “生成”Open the shortcut menu for your setup project and choose Build.

Windows Installer XML (WiX) 部署Windows Installer XML (WiX) deployment

Windows Installer XML (WiX) 工具集通过 XML 源代码生成 Windows 安装包。The Windows Installer XML (WiX) toolset builds Windows installation packages from XML source code. WiX 支持一种命令行环境,可以将其集成到你的生成过程中,以便生成 MSI 和 MSM 安装包。WiX supports a command-line environment that can be integrated into your build processes to build MSI and MSM setup packages. 通过使用 WiX,你可以 将 .NET Framework 指定为系统必备组件,或 创建链接器 来完全控制 .NET Framework 的部署体验。By using WiX, you can specify the .NET Framework as a prerequisite, or create a chainer to fully control the .NET Framework deployment experience. 有关 WiX 的更多信息,请参阅 Windows Installer XML (WiX) 工具集For more information about WiX, see the Windows Installer XML (WiX) toolset website.

手动安装 .NET FrameworkInstalling the .NET Framework manually

在某些情况下,随你的应用一起自动安装 .NET Framework 可能不切实际。In some situations, it might be impractical to automatically install the .NET Framework with your app. 此时,可以让用户自行安装 .NET Framework。In that case, you can have users install the .NET Framework themselves. 可再发行组件包通过 两个包提供。The redistributable package is available in two packages. 在安装过程中,请提供有关说明,介绍用户应如何查找并安装 .NET Framework。In your setup process, provide instructions for how users should locate and install the .NET Framework.

将 .NET Framework 安装链接到应用的安装程序Chaining the .NET Framework installation to your app's setup

如果要为你的应用创建自定义安装程序,则可以在应用的安装过程中链接(包括).NET Framework 安装过程。If you're creating a custom setup program for your app, you can chain (include) the .NET Framework setup process in your app's setup process. 链接提供了两种 .NET Framework 安装 UI 选项:Chaining provides two UI options for the .NET Framework installation:

  • 使用由 .NET Framework 安装程序提供的默认 UI。Use the default UI provided by the .NET Framework installer.

  • 为 .NET Framework 安装创建自定义 UI,与你的应用安装程序保持一致。Create a custom UI for the .NET Framework installation for consistency with your app's setup program.

这两种方法都允许使用 Web 安装程序或脱机安装程序。Both methods allow you to use either the web installer or the offline installer. 每个包都具有自己的优点:Each package has its advantages:

  • 如果使用 Web 安装程序,则 .NET Framework 安装过程将确定所需的安装包,然后从 Web 仅下载并安装该包。If you use the web installer, the .NET Framework setup process will decide which installation package is required, and download and install only that package from the web.

  • 如果使用脱机安装程序,则你可以在再发行介质中包括一套完整的 .NET Framework 安装包,以便用户在 Web 安装过程中不需要从 Web 下载任何其他文件。If you use the offline installer, you can include the complete set of .NET Framework installation packages with your redistribution media so that your users don't have to download any additional files from the web during setup.

使用默认 .NET Framework UI 进行链接Chaining by using the default .NET Framework UI

若要静默链接 .NET Framework 安装过程并由 .NET Framework 安装程序来提供 UI,请将下列命令添加到你的安装程序:To silently chain the .NET Framework installation process and let the .NET Framework installer provide the UI, add the following command to your setup program:

<.NET Framework redistributable> /q /norestart /ChainingPackage <PackageName>

例如,如果你的可执行程序是 Contoso.exe 并且希望静默安装 .NET Framework 4.5 脱机可再发行组件包,请使用以下命令:For example, if your executable program is Contoso.exe and you want to silently install the .NET Framework 4.5 offline redistributable package, use the command:

dotNetFx45_Full_x86_x64.exe /q /norestart /ChainingPackage Contoso

你可以使用其他命令行选项来自定义安装。You can use additional command-line options to customize the installation. 例如:For example:

  • 若要为用户提供一种方法来关闭运行中的 .NET Framework 应用,从而最大程度减少系统重新启动,请按照如下方式设置被动模式并使用 /showrmui 选项:To provide a way for users to close running .NET Framework apps to minimize system restarts, set passive mode and use the /showrmui option as follows:

    dotNetFx45_Full_x86_x64.exe /norestart /passive /showrmui /ChainingPackage Contoso
    

    此命令允许重新启动管理器显示一个消息框,用户可以在安装 .NET Framework 之前关闭 .NET Framework 应用。This command allows Restart Manager to display a message box that gives users the opportunity to close .NET Framework apps before installing the .NET Framework.

  • 如果使用 Web 安装程序,则可以使用 /LCID 选项来指定语言包。If you're using the web installer, you can use the /LCID option to specify a language pack. 例如,若要将 .NET Framework 4.5 Web 安装程序链接到 Contoso 安装程序并安装日语语言包,请将下列命令添加到应用的安装过程:For example, to chain the .NET Framework 4.5 web installer to your Contoso setup program and install the Japanese language pack, add the following command to your app's setup process:

    dotNetFx45_Full_setup.exe /q /norestart /ChainingPackage Contoso /LCID 1041
    

    如果省略 /LCID 选项,则安装程序将安装与用户的 MUI 设置匹配的语言包。If you omit the /LCID option, setup will install the language pack that matches the user's MUI setting.

    备注

    不同的语言包可能具有不同的发布日期。Different language packs may have different release dates. 如果下载中心不提供你所指定的语言包,则安装程序将安装不带语言包的 .NET Framework。If the language pack you specify is not available at the download center, setup will install the .NET Framework without the language pack. 如果用户计算机中已安装 .NET Framework,则安装程序将仅安装语言包。If the .NET Framework is already installed on the user’s computer, the setup will install only the language pack.

有关选项的完整列表,请参见 命名行选项 一节。For a complete list of options, see the Command-Line Options section.

有关常见的返回代码,请参见 返回代码 一节。For common return codes, see the Return Codes section.

使用自定义 UI 进行链接Chaining by Using a Custom UI

如果具有自定义安装包,你可能希望静默启动和跟踪 .NET Framework 安装过程,同时显示自己的安装进度视图。If you have a custom setup package, you may want to silently launch and track the .NET Framework setup while showing your own view of the setup progress. 这种情况下,请确保你的代码涵盖以下操作:If this is the case, make sure that your code covers the following:

  • 检查 .NET Framework 硬件和软件要求Check for .NET Framework hardware and software requirements.

  • 检测 用户计算机中是否已安装 .NET Framework 的正确版本。Detect whether the correct version of the .NET Framework is already installed on the user’s computer.

    重要

    确定是否安装了 .NET Framework 的正确版本时,应检查安装的是目标版本 还是 更高版本,而不是确定是否安装了目标版本。In determining whether the correct version of the .NET Framework is already installed, you should check whether your target version or a later version is installed, not whether your target version is installed. 换而言之,应检查从注册表中检索的版本密钥是否大于或等于目标版本的版本密钥,而 不是 检查其是否等于目标版本的版本密钥。In other words, you should evaluate whether the release key you retrieve from the registry is greater than or equal to the release key of your target version, not whether it equals the release key of your target version.

  • 检测 用户计算机中是否已安装语言包。Detect whether the language packs are already installed on the user’s computer.

  • 如果要控制部署,则静默启动并跟踪 .NET Framework 安装过程(请参阅如何:获取 .NET Framework 4.5 安装程序的进度If you want to control the deployment, silently launch and track the .NET Framework setup process (see How to: Get Progress from the .NET Framework 4.5 Installer).

  • 如果要部署脱机安装程序,则 单独链接语言包If you’re deploying the offline installer, chain the language packs separately.

  • 使用 命令行选项自定义部署。Customize deployment by using command-line options. 例如,如果要链接 .NET Framework Web 安装程序,但是想重写默认语言包,请使用 /LCID 选项(如上一节中所述)。For example, if you’re chaining the .NET Framework web installer, but you want to override the default language pack, use the /LCID option, as described in the previous section.

  • 疑难解答Troubleshoot.

检测 .NET FrameworkDetecting the .NET Framework

.NET Framework 安装程序会在安装成功时写入一些注册表项。The .NET Framework installer writes registry keys when installation is successful. 通过在注册表中检查 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full 文件夹中名为 Release 的值 DWORD,可以测试是否安装了 .NET Framework 4.5 或更高版本。You can test whether the .NET Framework 4.5 or later is installed by checking the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full folder in the registry for a DWORD value named Release. (请注意,“NET Framework Setup”不以句点开头。)存在此项即表明计算机中已安装 .NET Framework 4.5 或更高版本。(Note that "NET Framework Setup" doesn't begin with a period.) The existence of this key indicates that the .NET Framework 4.5 or a later version has been installed on that computer. Release 的值用于指示已安装的 .NET Framework 版本。The value of Release indicates which version of the .NET Framework is installed.

重要

当尝试检测是否存在特定版本时,应检查是否存在 大于或等于 版本关键字值的值。You should check for a value greater than or equal to the release keyword value when attempting to detect whether a specific version is present.

VersionVersion Release DWORD 的值Value of the Release DWORD
安装在 Windows 10 2018 年 4 月更新和 Windows Server 版本 1803 上的 .NET Framework 4.7.2.NET Framework 4.7.2 installed on Windows 10 April 2018 Update and on Windows Server, version 1803 461808461808
.NET Framework 4.7.2,安装在除 Windows 10 2018 年 4 月更新和 Windows Server 版本 1803 之外的所有 OS 版本上。.NET Framework 4.7.2 installed on all OS versions other than Windows 10 April 2018 Update, and Windows Server, version 1803. 这包括 Windows 10 2018 年 10 月更新。This includes Windows 10 October 2018 Update. 461814461814
安装在 Windows 10 秋季创意者更新和 Windows Server 版本 1709 上的 .NET Framework 4.7.1.NET Framework 4.7.1 installed on Windows 10 Fall Creators Update and on Windows Server, version 1709 461308461308
安装在除 Windows 10 秋季创意者更新和 Windows Server 版本 1709 之外的所有 OS 版本上的 .NET Framework 4.7.1.NET Framework 4.7.1 installed on all OS versions other than Windows 10 Fall Creators Update and Windows Server, version 1709 461310461310
在 Windows 10 创意者更新上安装的 .NET Framework 4.7.NET Framework 4.7 installed on Windows 10 Creators Update 460798460798
在除 Windows 10 创意者更新之外的所有操作系统版本上安装的 .NET Framework 4.7.NET Framework 4.7 installed on all OS versions other than Windows 10 Creators Update 460805460805
安装在 Windows 10 周年纪念版和 Windows Server 2016 上的 .NET Framework 4.6.2.NET Framework 4.6.2 installed on Windows 10 Anniversary Edition and on Windows Server 2016 394802394802
安装在除 Windows 10 周年纪念版和 Windows Server 2016 以外的所有 OS 版本上的 .NET Framework 4.6.2.NET Framework 4.6.2 installed on all OS versions other than Windows 10 Anniversary Edition and Windows Server 2016 394806394806
Windows 10 November Update 上安装的.NET Framework 4.6.1 .NET Framework 4.6.1 installed on Windows 10 November Update 394254394254
在 Windows 10 November Update 以外的所有操作系统版本上安装的.NET Framework 4.6.1 .NET Framework 4.6.1 installed on all OS versions other than Windows 10 November Update 394271394271
Windows 10 上安装的.NET Framework 4.6 .NET Framework 4.6 installed on Windows 10 393295393295
在 Windows 10 以外的所有操作系统版本上安装的.NET Framework 4.6 .NET Framework 4.6 installed on all OS versions other than Windows 10 393297393297
.NET Framework 4.5.2.NET Framework 4.5.2 379893379893
使用.NET Framework 4.5.1 或 Windows Server 2012 R2 安装的 Windows 8.1Windows 8.1 .NET Framework 4.5.1 installed with Windows 8.1Windows 8.1 or Windows Server 2012 R2 378675378675
.NET Framework 4.5.1 或 Windows 7 上安装的 Windows 8Windows 8installed on Windows 8Windows 8, Windows 7 378758378758
.NET Framework 4.5 378389378389

检测语言包Detecting the language packs

可以测试是否已安装特定语言包,方法是在注册表的 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\LCID 文件夹内查找名为 Release 的 DWORD 值。You can test whether a specific language pack is installed by checking the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\LCID folder in the registry for a DWORD value named Release. (请注意,“NET Framework Setup”不以句点开头。)LCID 指定一个区域设置标识符;有关这些标识符的列表,请参阅支持的语言(Note that "NET Framework Setup" doesn't begin with a period.) LCID specifies a locale identifier; see supported languages for a list of these.

例如,若要检测是否安装了完整的日语语言包 (LCID=1041),请在注册表中查找下列值:For example, to detect whether the full Japanese language pack (LCID=1041) is installed, check for the following values in the registry:

Key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\1041
Name: Release
Type: DWORD

若要确定是否已安装 .NET Framework 4.5 到 4.7.2 之间的某个特定版本的最终版本语言包,请按照前一部分检测 .NET Framework 中所述检查 RELEASE 项 DWORD 值的值。To determine whether the final release version of a language pack is installed for a particular version of the .NET Framework from 4.5 through 4.7.2, check the value of the RELEASE key DWORD value described in the previous section, Detecting the .NET Framework.

将语言包链接到应用安装程序Chaining the language packs to your app setup

.NET Framework 提供了一组独立的语言包可执行文件,其中包含适用于特定区域的本地化资源。The .NET Framework provides a set of stand-alone language pack executable files that contain localized resources for specific cultures. 这些语言包可以从 Microsoft 下载中心获得:The language packs are available from the Microsoft Download Center:

重要

语言包不包含运行应用所需的 .NET Framework 组件;你必须在安装语言包之前使用 Web 或脱机安装程序安装 .NET Framework。The language packs don't contain the .NET Framework components that are required to run an app; you must install the .NET Framework by using the web or offline installer before you install a language pack.

从 .NET Framework 4.5.1 开始,包名称采用以下形式 NDP<version>-KB<number>-x86-x64-AllOS-<culture>.exe,其中 version 是 .NET Framework 的版本号,number 是 Microsoft 知识库文章编号,culture 则指定国家/地区Starting with the .NET Framework 4.5.1, the package names take the form NDP<version>-KB<number>-x86-x64-AllOS-<culture>.exe, where version is the version number of the .NET Framework, number is a Microsoft Knowledge Base article number, and culture specifies a country/region. 例如, NDP452-KB2901907-x86-x64-AllOS-JPN.exe就是其中一个安装包。An example of one of these packages is NDP452-KB2901907-x86-x64-AllOS-JPN.exe. 包名称详见本文前面的 Redistributable Packages 一节。Package names are listed in the Redistributable Packages section earlier in this article.

若要随 .NET framework 脱机安装程序一起安装语言包,你必须将其链接到应用的安装程序。To install a language pack with the .NET Framework offline installer, you must chain it to your app's setup. 例如,若要部署带有日语语言包的 .NET Framework 4.5.1 脱机安装程序,请使用下列命令:For example, to deploy the .NET Framework 4.5.1 offline installer with the Japanese language pack, use the following command:

NDP451-KB2858728-x86-x64-AllOS-JPN.exe /q /norestart /ChainingPackage <ProductName>

如果使用 Web 安装程序,则不必链接语言包;安装程序将安装与用户的 MUI 设置匹配的语言包。You do not have to chain the language packs if you use the web installer; setup will install the language pack that matches the user's MUI setting. 如果要安装其他语言,则可以使用 /LCID 选项指定语言包。If you want to install a different language, you can use the /LCID option to specify a language pack.

有关命名行选项的完整列表,请参见 命名行选项 一节。For a complete list of command-line options, see the Command-Line Options section.

疑难解答Troubleshooting

返回代码Return codes

下表列出了 .NET Framework 可再发行安装程序的常见返回代码。The following table lists the most common return codes for the .NET Framework redistributable installer. 所有版本的安装程序的返回代码都是相同的。The return codes are the same for all versions of the installer. 有关详细信息的链接,请参见下一节。For links to detailed information, see the next section.

返回代码Return code 说明Description
00 已成功完成安装。Installation completed successfully.
16021602 用户已取消安装。The user canceled installation.
16031603 安装期间发生错误。A fatal error occurred during installation.
16411641 需要重新启动才能完成安装。A restart is required to complete the installation. 此消息指示安装成功。This message indicates success.
30103010 需要重新启动才能完成安装。A restart is required to complete the installation. 此消息指示安装成功。This message indicates success.
51005100 用户计算机不满足系统要求。The user's computer does not meet system requirements.

下载错误代码Download error codes

查看以下内容:See the following content:

其他错误代码Other error codes

查看以下内容:See the following content:

卸载 .NET FrameworkUninstalling the .NET Framework

Windows 8Windows 8 开始,你可以使用控制面板中的“打开或关闭 Windows 功能”来卸载 .NET Framework 4.5 或其中一个单点版本。Starting with Windows 8Windows 8, you can uninstall the .NET Framework 4.5 or one of its point releases by using Turn Windows features on and off in Control Panel. 在旧版本 Windows 中,你可以使用控制面板中的“添加或删除程序”来卸载 .NET Framework 4.5 或其中一个单点版本。In older versions of Windows, you can uninstall the .NET Framework 4.5 or one of its point releases by using Add or Remove Programs in Control Panel.

重要

对于 Windows 7 和更早的操作系统,卸载 .NET Framework 4.5.1、4.5.2、4.6、4.6.1、4.6.2、4.7、4.7.1 或 4.7.2 不会还原 .NET Framework 4.5 文件,并且卸载 .NET Framework 4.5 不会还原 .NET Framework 4 文件。For Windows 7 and earlier operating systems, uninstalling the .NET Framework 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, or 4.7.2 doesn't restore .NET Framework 4.5 files, and uninstalling the .NET Framework 4.5 doesn't restore .NET Framework 4 files. 如果要回到旧版本,你必须重新安装此版本及其任何更新。If you want to go back to the older version, you must reinstall it and any updates to it.

附录Appendix

命名行选项Command-line options

下表列出了将 .NET Framework 4.5 可再发行组件链接到应用安装程序时可以包括的选项。The following table lists options that you can include when you chain the .NET Framework 4.5 redistributable to your app's setup.

选项Option 说明Description
/CEIPConsent/CEIPConsent 覆盖默认行为并向 Microsoft 发送匿名反馈以改善将来的部署体验。Overwrites the default behavior and sends anonymous feedback to Microsoft to improve future deployment experiences. 仅当安装程序询问你是否同意安装并且用户授权向 Microsoft 发送匿名反馈时,才可以使用此选项。This option can be used only if the setup program prompts for consent and if the user grants permission to send anonymous feedback to Microsoft.
/chainingpackage packageName/chainingpackage packageName 指定执行链接的可执行文件的名称。Specifies the name of the executable that is doing the chaining. 向 Microsoft 发送此信息作为匿名反馈以帮助改进将来的部署体验。This information is sent to Microsoft as anonymous feedback to help improve future deployment experiences.

如果包名称包含空格,则可以用双引号作为分隔符;例如: /chainingpackage "Lucerne Publishing"If the package name includes spaces, use double quotation marks as delimiters; for example: /chainingpackage "Lucerne Publishing". 有关链接包的示例,请参阅 MSDN 库中的 从安装包获取进度信息For an example of a chaining package, see Getting Progress Information from an Installation Package in the MSDN Library.
/LCID LCID/LCID LCID

其中 LCID 指定一个区域设置标识符(请参见 支持的语言where LCID specifies a locale identifier (see supported languages)
安装由 LCID 指定的语言包,并强制使用此语言显示 UI(除非设置为安静模式)。Installs the language pack specified by LCID and forces the displayed UI to be shown in that language, unless quiet mode is set.

对于 Web 安装程序,此选项将从 Web 链接并安装语言包。For the web installer, this option chain-installs the language package from the web. 注意: 只能随 Web 安装程序一起使用此选项。Note: Use this option only with the web installer.
/log file | folder/log file | folder 指定日志文件的位置。Specifies the location of the log file. 默认为过程的临时文件夹,默认文件名基于安装包。The default is the temporary folder for the process, and the default file name is based on the package. 如果文件扩展名为 .txt,则生成文本日志。If the file extension is .txt, a text log is produced. 如果指定其他扩展名或不指定扩展名,则创建 HTML 日志。If you specify any other extension or no extension, an HTML log is created.
/msioptions/msioptions 指定要为 .msi 和 .msp 项传递的选项;例如: /msioptions "PROPERTY1='Value'"Specifies options to be passed for .msi and .msp items; for example: /msioptions "PROPERTY1='Value'".
/norestart/norestart 防止安装程序自动重新启动。Prevents the setup program from rebooting automatically. 如果使用此选项,则链接应用必须捕获返回代码并处理重新启动操作(请参阅 MSDN 库中的 从安装包获取进度信息 )。If you use this option, the chaining app has to capture the return code and handle rebooting (see Getting Progress Information from an Installation Package in the MSDN Library).
/passive/passive 设置被动模式。Sets passive mode. 显示用于指示安装正在进行的进度栏,但不向用户显示任何提示或错误消息。Displays the progress bar to indicate that installation is in progress, but does not display any prompts or error messages to the user. 在此模式下,当链接包被安装程序链接时,它必须处理 返回代码In this mode, when chained by a setup program, the chaining package must handle return codes.
/pipe/pipe 创建一个信道,使链接包可以获取进度。Creates a communication channel to enable a chaining package to get progress.
/promptrestart/promptrestart 仅在被动模式下,如果安装程序需要重新启动,则会提示用户。Passive mode only, if the setup program requires a restart, it prompts the user. 如果需要重新启动,则此选项会要求用户进行交互。This option requires user interaction if a restart is required.
/q/q 设置安静模式。Sets quiet mode.
/repair/repair 触发修复功能。Triggers the repair functionality.
/serialdownload/serialdownload 强制仅在已下载安装包后才进行安装。Forces the installation to happen only after the package has been downloaded.
/showfinalerror/showfinalerror 设置被动模式。Sets passive mode. 仅在安装未成功时显示错误。Displays errors only if the installation is not successful. 如果安装未成功,则此选项要求用户交互。This option requires user interaction if the installation is not successful.
/showrmui/showrmui 仅与 /passive 选项一起使用。Used only with the /passive option. 显示一个消息框,提示用户关闭当前正在运行的 .NET Framework 应用。Displays a message box that prompts users to close .NET Framework apps that are currently running. 此消息框在被动和非被动模式下具有相同的行为。This message box behaves the same in passive and non-passive mode.
/uninstall/uninstall 卸载 .NET Framework 可再发行组件。Uninstalls the .NET Framework redistributable.

支持的语言Supported languages

下表列出了可用于 .NET Framework 4.5 及其单点版本的 .NET Framework 语言包。The following table lists .NET Framework language packs that are available for the .NET Framework 4.5 and its point releases.

LCIDLCID 语言 - 国家/地区Language – country/region cultureCulture
10251025 阿拉伯语 - 沙特阿拉伯Arabic - Saudi Arabia arar
10281028 中文 - 繁体Chinese – Traditional zh-Hantzh-Hant
10291029 捷克语Czech cscs
10301030 丹麦语Danish dada
10311031 德语 - 德国German – Germany dede
10321032 希腊语Greek elel
10351035 芬兰语Finnish fifi
10361036 法语 - 法国French – France frfr
10371037 希伯来语Hebrew hehe
10381038 匈牙利语Hungarian huhu
10401040 意大利语 - 意大利Italian – Italy itit
10411041 日语Japanese jaja
10421042 朝鲜语Korean koko
10431043 荷兰语 - 荷兰Dutch – Netherlands nlnl
10441044 挪威语(博克马尔语)Norwegian (Bokmål) no
10451045 波兰语Polish plpl
10461046 葡萄牙语 - 巴西Portuguese – Brazil pt-BRpt-BR
10491049 俄语Russian ruru
10531053 瑞典语Swedish svsv
10551055 土耳其语Turkish trtr
20522052 中文 - 简体Chinese – Simplified zh-Hanszh-Hans
20702070 葡萄牙语 - 葡萄牙Portuguese – Portugal pt-PTpt-PT
30823082 西班牙语 - 西班牙(现代排序)Spanish - Spain (Modern Sort) eses

请参阅See also