使用命令列參數來安裝 Visual StudioUse command-line parameters to install Visual Studio

當您從命令提示字元安裝 Visual Studio 時,可以使用各種命令列參數來控制或自訂安裝。When you install Visual Studio 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:

命令列參數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.)

Tip

如需如何使用命令列安裝 Visual Studio 的更多範例,請參閱命令列參數範例頁面。For more examples of how to use the command line to install Visual Studio, 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.
export 15.9 版的新功能:將安裝選取項目匯出至安裝組態檔。New in version 15.9: Exports installation selection to an installation configuration file. 注意:僅能透過 vs_installer.exe 使用。Note: Can only be used with vs_installer.exe.

安裝選項Install options

安裝選項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> 選擇性:一或多個要新增的工作負載或元件識別碼。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. 若要包含多個工作負載或元件,請重複 --add 命令 (例如 --add Workload1 --add Workload2)。To include multiple workloads or components, repeat the --add command (for example, --add Workload1 --add Workload2). 若要進行更精細的控制,可將 ;includeRecommended;includeOptional 附加到識別碼 (例如 --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). 如需詳細資訊,請參閱工作負載與元件識別碼頁面。For more information, see the Workload and component IDs page. 如有必要,您可以重複此選項。You can repeat this option as necessary.
--remove <one or more workload or component IDs> 選擇性:一或多個要移除的工作負載或元件識別碼。Optional: One or more workload or component IDs to remove. 如需詳細資訊,請參閱工作負載和元件識別碼 (英文) 頁面。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 necessary). 如果未指定 --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. 此金鑰是以 xxxxx-xxxxx-xxxxx-xxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 格式,由 25 個英數字元構成的。It 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.
--config <path> 選擇性15.9 中的新功能:在安裝或修改作業期間,這會根據先前儲存的安裝組態檔,來決定要新增的工作負載和元件。Optional and New in 15.9: During an install or modify operation, this determines the workloads and components to add based on a previously saved installation configuration file. 這是累加作業,不會移除檔案中沒有的任何工作負載或元件。This operation is additive and it will not remove any workload or component if they are not present in the file. 此外,不會新增未套用至產品的項目。Also, items that do not apply to the product will not be added. 在匯出作業期間,這會決定安裝組態檔的儲存位置。During an export operation, this determines the location to save the installation configuration file.

Important

指定多個工作負載和元件時,您必須針對每個項目重複 --add--remove 命令列參數。When specifying multiple workloads and components, you must repeat the --add or --remove command-line switch for each item.

配置選項Layout options

配置選項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> 選擇性:一或多個要新增的工作負載或元件識別碼。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 附加到識別碼 (例如 --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). 如需詳細資訊,請參閱工作負載與元件識別碼頁面。For more information, see the 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 redownloaded. 必須有網際網路存取權才可修正配置。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> 選擇性:要安裝執行個體的通道識別碼。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)。此選項可用於安裝命令,但針對其他命令則會予以略過。(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. 此選項可用於安裝命令,但針對其他命令則會予以略過。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. 此選項可用於安裝命令,但針對其他命令則會予以略過。This can be used for the install command; it is ignored for other commands.
--productId <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 中的選擇性新功能:如果存在,Visual Studio 安裝程式就會使用您配置目錄中的檔案來安裝 Visual Studio。New in 15.3, optional: If present, Visual Studio setup uses the files in your layout directory to install Visual Studio. 如果使用者嘗試安裝不是在該配置中的元件,安裝程式將會失敗。If a user tries to install components that are not in the layout, setup fails. 如需詳細資訊,請參閱從網路安裝部署For more information, see Deploying from a network installation.

重要:此參數不會阻止 Visual Studio 安裝程式檢查更新。Important: This switch does not stop Visual Studio setup from checking for updates. 如需詳細資訊,請參閱控制網路型 Visual Studio 部署的更新For more information, see Control updates to network-based Visual Studio deployments.
--path <name>=<path> 15.7 中的選擇性新功能:用來指定安裝的自訂安裝路徑。New in 15.7, optional: Used to specify custom install paths for the installation. 支援的路徑名稱為 shared、cache 和 install。Supported path names are shared, cache, and install.
--path cache=<path> 15.7 中的選擇性新功能:使用您指定用於下載安裝檔案的位置。New in 15.7, optional: Uses the location you specify to download installation files. 此位置只能在第一次安裝 Visual Studio 時設定。This location can only be set the first time that Visual Studio is installed. 範例:--path cache="C:\VS\cache"Example: --path cache="C:\VS\cache"
--path shared=<path> 15.7 中的選擇性新功能:包含並存 Visual Studio 安裝的共用檔案。New in 15.7, optional: Contains shared files for side-by-side Visual Studio installations. 某些工具和 SDK 會安裝到此磁碟機上的位置,而其他一些項目則可能會覆寫此設定並安裝到其他磁碟機。Some tools and SDKs install to a location on this drive, while some others might override this setting and install to another drive. 範例:--path shared="C:\VS\shared"Example: --path shared="C:\VS\shared"

重要事項:此項目只能在第一次安裝 Visual Studio 時設定一次。Important: This can be set only once and on the first time that Visual Studio is installed.
--path install=<path> 15.7 中的選擇性新功能:相當於 –-installPathNew in 15.7, optional: Equivalent to –-installPath. 特別是 --installPath "C:\VS"--path install="C:\VS" 相等。Specifically, --installPath "C:\VS" and --path install="C:\VS" are equivalent. 一次只能使用其中一個。Only one of these can be used at a time.

工作負載識別碼和元件識別碼清單List of workload IDs and component IDs

如需依 Visual Studio 產品排序的工作負載和元件識別碼清單,請參閱 Visual Studio 工作負載和元件識別碼頁面。For a list of workload and component IDs sorted by Visual Studio product, see the Visual Studio workload and component IDs page.

語言地區設定清單List of language locales

語言地區設定Language-locale LanguageLanguage
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 is 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_bootstrapperdd_clientdd_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 安裝和升級問題進行疑難排解中的逐步說明。If your Visual Studio installation fails, see Troubleshooting Visual Studio installation and upgrade issues for step-by-step guidance.

我們也提供即時聊天 (僅限英文) 支援選項,可回答有關安裝的相關問題。We also offer a live chat (English only) support option for installation-related issues.

以下是一些支援選項:Here are a few more support options:

另請參閱See also