使用命令行参数安装 Visual Studio 2017Use command-line parameters to install Visual Studio 2017

通过命令提示符安装 Visual Studio 2017 时,可以使用各种命令行参数来控制或自定义安装。When you install Visual Studio 2017 from a command prompt, you can use a variety of command-line parameters to control or customize the installation. 通过命令行,可以执行下列操作:From the command line, you can perform the following actions:

  • 启动预先选定了特定选项的安装。Start the install with certain options preselected.
  • 自动执行安装过程。Automate the installation process.
  • 创建安装文件的缓存(布局)以备日后使用。Create a cache (layout) of the installation files for later use.

将命令行选项与安装引导程序结合使用。安装引导程序是启动下载过程的小型(约 1MB)文件。The command-line options are used in conjunction with the setup bootstrapper, which is the small (approximately 1MB) file that initiates the download process. 安装引导程序是你从 Visual Studio 网站下载时启动的第一个可执行文件。The bootstrapper is the first executable that is launched when you download from the Visual Studio site. 单击下面的链接,直接链接到要安装的产品版本所对应的最新版安装引导程序:Use the following links to get a direct link to the latest release bootstrapper for the product edition that you're installing:

命令行参数列表List of command-line parameters

Visual Studio 命令行参数不区分大小写。Visual Studio command-line parameters are case-insensitive.

语法:vs_enterprise.exe [command] <options>...Syntax: vs_enterprise.exe [command] <options>...

(将 vs_enterprise.exe 替换为要安装的相应产品版本。)(Replace vs_enterprise.exe as appropriate for the product edition you're installing.)

提示

有关如何使用命令行安装 Visual Studio 2017 的更多示例,请参阅命令行参数示例页。For more examples of how to use the command line to install Visual Studio 2017, see the Command-line parameter examples page.)

命令Command 说明Description
(空白)(blank) 安装产品。Installs the product.
modify 修改已安装的产品。Modifies an installed product.
update 更新已安装的产品。Updates an installed product.
repair 修复已安装的产品。Repairs an installed product.
uninstall 卸载已安装的产品。Uninstalls an installed product.
安装选项Install option 说明Description
--installPath <dir> 要对其执行操作的实例的安装目录。The installation directory for the instance to act upon. 对于安装命令,这是可选选项,表示实例的安装位置。For the install command, this is Optional and is where the instance will be installed. 对于其他命令,此为必需选项,表示以前安装的实例的安装位置。For other commands, this is Required and is where the previously installed instance was installed.
--addProductLang <language-locale> 可选:在安装或修改操作期间,这可确定要在产品中安装的 UI 语言包。Optional: During an install or modify operation, this determines the UI language packs that are installed to the product. 可以在命令行处多次使用此选项,从而添加多个语言包。It can appear multiple times on the command line to add multiple language packs. 如果缺少此选项,将使用计算机区域设置进行安装。If not present, the installation uses the machine locale. 有关详细信息,请参阅本页的语言区域设置列表部分。For more information, see the List of language locales section on this page.
--removeProductLang <language-locale> 可选:在安装或修改操作期间,这可确定要从产品中删除的 UI 语言包。Optional: During an install or modify operation, this determines the UI language packs that are to be removed from the product. 可以在命令行处多次使用此选项,从而添加多个语言包。It can appear multiple times on the command line to add multiple language packs. 有关详细信息,请参阅本页的语言区域设置列表部分。For more information, see the List of language locales section on this page.
--add <one or more workload or component IDs> 可选:要添加的一个或多个工作负荷或组件 ID。Optional: One or more workload or component IDs to add. 将安装项目的所需组件,而不是建议组件或可选组件。The required components of the artifact are installed, but not the recommended or optional components. 可以使用 --includeRecommended 和/或 --includeOptional 全局控制其他组件。You can control additional components globally using --includeRecommended and/or --includeOptional. 若要更精确地进行控制,可以将 ;includeRecommended;includeOptional 追加到 ID 中(例如,--add Workload1;includeRecommended--add Workload2;includeRecommended;includeOptional)。For finer-grained control, you can append ;includeRecommended or ;includeOptional to the ID (for example, --add Workload1;includeRecommended or --add Workload2;includeRecommended;includeOptional). 有关详细信息,请参阅工作负载和组件 ID 页。For more information, see our Workload and component IDs page. 可以根据需要重复此选项。You can repeat this option as necessary.
--remove <one or more workload or component IDs> 可选:要删除的一个或多个工作负荷或组件 ID。Optional: One or more workload or component IDs to remove. 有关详细信息,请参阅工作负载和组件 ID 页。For more information, see our Workload and component IDs page. 可以根据需要重复此选项。You can repeat this option as necessary.
--in <path> 可选:响应文件的 URI 或路径。Optional: The URI or path to a response file.
--all 可选:是否安装产品的所有工作负荷和组件。Optional: Whether to install all workloads and components for a product.
--allWorkloads 可选:安装所有工作负载和组件,不安装建议组件或可选组件。Optional: Installs all workloads and components, no recommended or optional components.
--includeRecommended 可选:包含所有已安装工作负载的推荐组件,但不包含可选组件。Optional: Includes the recommended components for any workloads that are installed, but not the optional components. 可使用 --allWorkloads--add 指定工作负载。The workloads are specified either with --allWorkloads or --add.
--includeOptional 可选:包含所有已安装工作负荷的可选组件,但不包含建议组件。Optional: Includes the optional components for any workloads that are installed, but not the recommended components. 可使用 --allWorkloads--add 指定工作负载。The workloads are specified either with --allWorkloads or --add.
--quiet, -q 可选:执行安装时不显示任何用户界面。Optional: Do not display any user interface while performing the installation.
--passive, -p 可选:显示用户界面,但不请求用户进行任何交互。Optional: Display the user interface, but do not request any interaction from the user.
--norestart 可选:如果指定,包含 --passive--quiet 的命令不会自动重启计算机(如有必要)。Optional: If present, commands with --passive or --quiet will not automatically restart the machine (if required). 如果 --passive--quiet 均未指定,则忽略此选项。This is ignored if neither --passive nor --quiet are specified.
--nickname <name> 可选:此参数定义分配给已安装产品的别名。Optional: This defines the nickname to assign to an installed product. 别名长度不能超过 10 个字符。The nickname cannot be longer than 10 characters.
--productKey 可选:这定义要用于已安装产品的产品密钥。Optional: This defines the product key to use for an installed product. 由 25 个字母数字字符组成,格式为 xxxxx-xxxxx-xxxxx-xxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxIt is composed of 25 alphanumeric characters either in the format xxxxx-xxxxx-xxxxx-xxxxx-xxxxx or xxxxxxxxxxxxxxxxxxxxxxxxx.
--help, --?, -h, -? 显示此页的脱机版本。Display an offline version of this page.

注意:指定多个工作负载和组件时,必须对每项重复运行 --add--remove 命令行开关。Note: When specifying multiple workloads and components, you must repeat the --add or --remove command-line switch for each item.

布局选项Layout options 说明Description
--layout <dir> 指定用于创建脱机安装缓存的目录。Specifies a directory to create an offline install cache. 有关详细信息,请参阅创建 Visual Studio 的网络安装For more information, see Create a network-based installation of Visual Studio.
--lang <one or more language-locales> 可选:与 --layout 结合使用,以准备脱机安装缓存,以便使用包含指定语言的资源包。Optional: Used with --layout to prepare an offline install cache with resource packages with the specified language(s). 有关详细信息,请参阅本页的语言区域设置列表部分。For more information, see the List of language locales section on this page.
--add <one or more workload or component IDs> 可选:要添加的一个或多个工作负荷或组件 ID。Optional: One or more workload or component IDs to add. 将安装项目的所需组件,而不是建议组件或可选组件。The required components of the artifact are installed, but not the recommended or optional components. 可以使用 --includeRecommended 和/或 --includeOptional 全局控制其他组件。You can control additional components globally using --includeRecommended and/or --includeOptional. 若要更精确地进行控制,可以将 ;includeRecommended;includeOptional 追加到 ID 中(例如,--add Workload1;includeRecommended--add Workload2;includeOptional)。For finer-grained control, you can append ;includeRecommended or ;includeOptional to the ID (for example, --add Workload1;includeRecommended or --add Workload2;includeOptional). 有关详细信息,请参阅工作负载和组件 ID 页。For more information, see our Workload and component IDs page.
注意:如果使用了 --add,只会下载指定的工作负载和组件及其依赖项。Note: If --add is used, only the specified workloads and components and their dependencies are downloaded. 如果未指定 --add,所有工作负载和组件都会下载到布局中。If --add is not specified, all workloads and components are downloaded to the layout.
--includeRecommended 可选:包含所有已安装工作负载的推荐组件,但不包含可选组件。Optional: Includes the recommended components for any workloads that are installed, but not the optional components. 可使用 --allWorkloads--add 指定工作负载。The workloads are specified either with --allWorkloads or --add.
--includeOptional 可选:添加布局中包含的任何工作负载的推荐可选组件。Optional: Includes the recommended and optional components for any workloads being included in the layout. 可使用 --add 指定工作负载。The workloads are specified with --add.
--keepLayoutVersion 15.3 中新增的可选选项:无需更新布局版本,即可将更改应用到布局中。New in 15.3, optional: Apply changes to the layout without updating the version of the layout.
--verify 15.3 中新增的可选选项:验证布局内容。New in 15.3, optional: Verify the contents of a layout. 将列出所有损坏或缺失的文件。Any corrupt or missing files are listed.
--fix 15.3 中新增的可选选项:验证布局内容。New in 15.3, optional: Verify the contents of a layout. 如果发现任何文件损坏或缺失,将重新进行下载。If any files are found to be corrupt or missing, they are re-downloaded. 必须连接 Internet,才能修复布局。Internet access is required to fix a layout.
--clean <one or more paths to catalogs> 15.3 中新增的可选选项:从已更新到新版本的布局中删除旧版组件。New in 15.3, optional: Removes old versions of components from a layout that has been updated to a newer version.
高级安装选项Advanced install options 说明Description
--channelId <id> 可选:要安装的实例的通道 ID。Optional: The ID of the channel for the instance to be installed. 如果指定了 --installPath,对于安装命令,此为是必需选项,对于其他命令,此选项可忽略。This is required for the install command, ignored for other commands if --installPath is specified.
--channelUri <uri> 可选:通道清单的 URI。Optional: The URI of the channel manifest. 如果不需要更新,--channelUri 可以指向不存在的文件。If updates are not desired, --channelUri can point to a non-existent file. (例如,--channelUri C:\doesntExist.chman)此参数可用于 install 命令;其他命令则可忽略。(for example, --channelUri C:\doesntExist.chman) This can be used for the install command; it is ignored for other commands.
--installChannelUri <uri> 可选:要用于安装的通道清单的 URI。Optional: The URI of the channel manifest to use for the installation. --channelUri 指定的 URI(指定 --installChannelUri 时必须指定)用于检测更新。The URI specified by --channelUri (which must be specified when --installChannelUri is specified) is used to detect updates. 此参数可用于 install 命令;其他命令则可忽略。This can be used for the install command; it is ignored for other commands.
--installCatalogUri <uri> 可选:要用于安装的目录清单的 URI。Optional: The URI of the catalog manifest to use for the installation. 如果指定此选项,通道管理器会先尝试通过此 URI 下载目录清单,然后再在安装通道清单中使用 URI。If specified, the channel manager attempts to download the catalog manifest from this URI before using the URI in the install channel manifest. 此参数用于支持脱机安装,安装期间会使用已下载的产品目录创建布局缓存。This parameter is used to support offline install, where the layout cache will be created with the product catalog already downloaded. 此参数可用于 install 命令;其他命令则可忽略。This can be used for the install command; it is ignored for other commands.
--productId <id> 可选:将要安装的实例的产品 ID。Optional The ID of the product for the instance that will be installed. 在正常安装条件下,这是预填充的。This is prepopulated in normal installation conditions.
--wait 可选:进程会先等待安装完成,然后再返回退出代码。Optional: The process will wait until the install is completed before returning an exit code. 在需要等待安装完成以处理来自该安装的返回代码的自动安装中,这非常有用。This is useful when automating installations where one needs to wait for the install to finish to handle the return code from that install.
--locale <language-locale> 可选:更改安装程序本身的用户界面的显示语言。Optional: Change the display language of the user interface for the installer itself. 将保留设置。Setting will be persisted. 有关详细信息,请参阅本页的语言区域设置列表部分。For more information, see the List of language locales section on this page.
--cache 15.2 中的新增选项,可选:如果指定,将在安装后保存包,以便后续修复时使用。New in 15.2, optional: If present, packages will be kept after being installed for subsequent repairs. 这会替代用于后续安装、修复或修改的全局策略设置。This overrides the global policy setting to be used for subsequent installs, repairs, or modifications. 默认策略是缓存包。The default policy is to cache packages. 对于卸载命令,忽略此选项。This is ignored for the uninstall command. 有关详细信息,请了解如何禁用或移动包缓存Read how to disable or move the package cache for more information.
--nocache 15.2 中新增的可选选项:如果指定,将在安装或修复完成后删除包。New in 15.2, optional: If present, packages will be deleted after being installed or repaired. 只有在需要时才会重新下载,并且会在使用后再次删除。They will be downloaded again only if needed and deleted again after use. 这会替代用于后续安装、修复或修改的全局策略设置。This overrides the global policy setting to be used for subsequent installs, repairs, or modifications. 默认策略是缓存包。The default policy is to cache packages. 对于卸载命令,忽略此选项。This is ignored for the uninstall command. 有关详细信息,请了解如何禁用或移动包缓存Read how to disable or move the package cache for more information.
--noUpdateInstaller 15.2 中的新增功能(可选):如果存在,指定无提示安装时阻止安装程序进行自我更新。New in 15.2, optional: If present, prevents the installer from updating itself when quiet is specified. 如果在需要更新安装程序时通过无提示安装指定 noUpdateInstaller,则安装程序将忽略该命令并返回非零退出代码。The installer will fail the command and return a non-zero exit code if noUpdateInstaller is specified with quiet when an installer update is required.
--noWeb 15.3 中新增的可选选项:安装程序现在从 Internet 下载要安装的所有内容。New in 15.3, optional: Setup now downloads any content that it is installing from the Internet. 离线布局中必须有要安装的所有内容。All content that is being installed must be available in an offline layout. 如果布局中缺少内容,安装将失败。If the layout is missing content, setup fails. 有关详细信息,请参阅从网络安装点进行部署For more information, see Deploying from a network installation.

工作负荷 ID 和组件 ID 列表List of workload IDs and component IDs

有关按 Visual Studio 产品排序的工作负载和组件 ID 的列表,请参阅 Visual Studio 2017 工作负载和组件 ID 页面。For a list of workload and component IDs sorted by Visual Studio product, see the Visual Studio 2017 Workload and Component IDs page.

语言区域设置列表List of language locales

语言-区域设置Language-locale 语言Language
cs-CZcs-CZ 捷克语Czech
de-DEde-DE 德语German
en-USen-US 英语English
es-ESes-ES 西班牙语Spanish
fr-FRfr-FR 法语French
it-ITit-IT 意大利语Italian
ja-JPja-JP 日语Japanese
ko-KRko-KR 朝鲜语Korean
pl-PLpl-PL 波兰语Polish
pt-BRpt-BR 葡萄牙语 - 巴西Portuguese - Brazil
ru-RUru-RU 俄语Russian
tr-TRtr-TR 土耳其语Turkish
zh-CNzh-CN 中文 - 简体Chinese - Simplified
zh-TWzh-TW 中文 - 繁体Chinese - Traditional

错误代码Error codes

%ERRORLEVEL% 环境变量设为下列值之一,具体视操作结果而定:Depending on the result of the operation, the %ERRORLEVEL% environment variable will be set to one of the following values:

Value 结果Result
00 操作成功完成Operation completed successfully
16021602 操作已取消Operation was canceled
30103010 操作成功完成,但安装需要重启才能使用Operation completed successfully, but install requires reboot before it can be used
50045004 操作已取消Operation was canceled
50075007 操作被屏蔽 - 计算机不符合要求Operation was blocked - the computer does not meet the requirements
其他Other 发生了故障,请查看日志,了解详细信息Failure condition occurred - check the logs for more information

每个操作都会在指明安装进度的 %TEMP% 目录中生成多个日志文件。Each operation generates several log files in the %TEMP% directory that indicate the progress of the installation. 按日期对文件夹进行排序,再查找以“dd_bootstrapper”、“dd_client”和“dd_setup”开头的文件,分别查找安装引导程序、安装程序应用和安装程序引擎。Sort the folder by date and look for files that begin with dd_bootstrapper, dd_client, and dd_setup for the bootstrapper, the installer app, and the setup engine, respectively.

获取支持Get support

有时也会遇到问题。Sometimes, things can go wrong. 如果 Visual Studio 安装失败,请参阅 Visual Studio 2017 安装和升级问题疑难解答页。If your Visual Studio installation fails, see the Troubleshooting Visual Studio 2017 installation and upgrade issues page. 如果所有的疑难解答步骤都没有帮助,请通过实时聊天与我们联系,以获得安装帮助(仅限英语)。If none of the troubleshooting steps help, you can contact us by live chat for installation assistance (English only). 有关详细信息,请参阅 Visual Studio 支持页For details, see the Visual Studio support page.

下面是另外几个支持选项:Here are a few more support options:

请参阅See also