Visual Studio 2017 安裝的命令列參數範例Command-line parameter examples for Visual Studio 2017 installation

為了說明如何使用命令列參數安裝 Visual Studio,以下是幾個範例,您可以自訂以符合您的需求。To illustrate how to use command-line parameters to install Visual Studio, here are several examples that you can customize to match your needs.

在每個範例中,vs_enterprise.exevs_professional.exevs_community.exe 表示 Visual Studio 啟動載入器的個別版本,這是起始下載程序的小型檔案 (約 1 MB)。In each example, vs_enterprise.exe, vs_professional.exe and vs_community.exe represent the respective edition of the Visual Studio bootstrapper, which is the small (approximately 1MB) file that initiates the download process. 如果您使用不同的版本,請取代為適當的啟動載入器名稱。If you are using a different edition, substitute the appropriate bootstrapper name.

Note

所有命令都需要提升系統管理權限,如果未從已提升權限的提示字元啟動程序,則會顯示 [使用者帳戶控制] 提示。All commands require administrative elevation, and a User Account Control prompt will be displayed if the process is not started from an elevated prompt.

Note

您可以在命令列結尾處使用 ^ 字元,將多行串連成單一命令。You can use the ^ character at the end of a command line to concatenate multiple lines into a single command. 或者,您也可以直接將這幾行放到一列。Alternatively, you can simply place these lines together onto a single row. 在 PowerShell 中,對等項目為倒引號 (`) 字元。In PowerShell, the equivalent is the backtick (`) character.

使用 --installPathUsing --installPath

  • 安裝 Visual Studio 的最小執行個體,不會顯示互動式提示,但會顯示進度:Install a minimal instance of Visual Studio, with no interactive prompts but progress displayed:

    vs_enterprise.exe --installPath C:\minVS ^
    --add Microsoft.VisualStudio.Workload.CoreEditor ^
    --passive --norestart
    
  • 使用命令列更新 Visual Studio 執行個體,不顯示互動式提示,但顯示進度:Update a Visual Studio instance by using the command line, with no interactive prompts but progress displayed:

    vs_enterprise.exe --update --quiet --wait
    vs_enterprise.exe update --wait --passive --norestart --installPath "C:\installPathVS"
    

    Note

    兩個命令都是必要的。Both commands are required. 第一個命令更新 Visual Studio 安裝程式。The first command updates the Visual Studio Installer. 第二個命令更新 Visual Studio 執行個體。The second command updates the Visual Studio instance. 若要避免 [使用者帳戶控制] 對話方塊,請以系統管理員身分執行命令提示字元。To avoid a User Account Control dialog, run the command prompt as an Administrator.

  • 使用法文語言套件以無訊息方式安裝 Visual Studio 的桌面執行個體,並只在安裝產品時傳回。Install a desktop instance of Visual Studio silently, with the French language pack, returning only when the product is installed.

    vs_enterprise.exe --installPath C:\desktopVS ^
    --addProductLang fr-FR ^
    --add Microsoft.VisualStudio.Workload.ManagedDesktop ^
    --includeRecommended --quiet --wait
    

    Note

    --wait 參數是專為在批次檔中使用所設計。The --wait parameter is designed for use in a batch file. 在批次檔中,直到安裝完成之後,才會繼續執行下一個命令。In a batch file, execution of the next command will not continue until the installation has completed. %ERRORLEVEL% 環境變數會包含命令的傳回值,如使用命令列參數安裝 Visual Studio 頁面中所述。The %ERRORLEVEL% environment variable will contain the return value of the command, as documented in the Use command-line parameters to install Visual Studio page.

使用 --layoutUsing --layout

  • 下載 Visual Studio 核心編輯器 (最基本的 Visual Studio 設定)。Download the Visual Studio core editor (the most minimal Visual Studio configuration). 只包含英文語言套件:Only include the English language pack:

    vs_community.exe --layout C:\VS2017
    --lang en-US ^
    --add Microsoft.VisualStudio.Workload.CoreEditor
    
  • 下載 .NET 桌面和 .NET Web 工作負載,以及所有建議的元件和 GitHub 延伸模組。Download the .NET desktop and .NET web workloads along with all recommended components and the GitHub extension. 只包含英文語言套件:Only include the English language pack:

    vs_community.exe --layout C:\VS2017 ^
    --lang en-US ^
    --add Microsoft.VisualStudio.Workload.NetWeb ^
    --add Microsoft.VisualStudio.Workload.ManagedDesktop ^
    --add Component.GitHub.VisualStudio ^
    --includeRecommended
    

使用 --includeRecommendedUsing --includeRecommended

  • 啟動 Visual Studio 2017 Enterprise 版中可用之所有工作負載和元件的互動式安裝:Start an interactive installation of all workloads and components that are available in the Visual Studio 2017 Enterprise edition:

    vs_enterprise.exe --all --includeRecommended --includeOptional
    
  • 在已安裝 Visual Studio 2017 Community 版的電腦上安裝第二個名為 Visual Studio 2017 Professional 的執行個體,並提供 Node.js 開發的支援:Install a second, named instance of Visual Studio 2017 Professional on a machine with Visual Studio 2017 Community edition already installed, with support for Node.js development:

    vs_professional.exe --installPath C:\VSforNode ^
    --add Microsoft.VisualStudio.Workload.Node --includeRecommended --nickname VSforNode
    

使用 --removeUsing --remove

  • 從預設安裝的 Visual Studio 執行個體移除程式碼剖析工具元件:Remove the Profiling Tools component from the default installed Visual Studio instance:

    vs_enterprise.exe modify ^
    --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise" ^
    --remove Microsoft.VisualStudio.Component.DiagnosticTools ^
    --passive
    

使用 --pathUsing --path

這些命令列參數是在 15.7 中新增的These command-line parameters are new in 15.7. 如需詳細資訊,請參閱 Use command-line parameters to install Visual Studio (使用命令列參數安裝 Visual Studio) 頁面。For more information about them, see the Use command-line parameters to install Visual Studio page.

  • 使用安裝、快取和共用路徑:Using the install, cache, and shared paths:

    vs_enterprise.exe --add Microsoft.VisualStudio.Workload.CoreEditor --path install="C:\VS" --path cache="C:\VS\cache" --path shared="C:\VS\shared"

  • 只使用安裝和快取路徑:Using only the install and cache paths:

    vs_enterprise.exe --add Microsoft.VisualStudio.Workload.CoreEditor --path install="C:\VS" --path cache="C:\VS\cache"

  • 只使用安裝和共用路徑:Using only the install and shared paths:

    vs_enterprise.exe --add Microsoft.VisualStudio.Workload.CoreEditor --path install="C:\VS" --path shared="C:\VS\shared"

  • 只使用安裝路徑:Using only the install path:

    vs_enterprise.exe --add Microsoft.VisualStudio.Workload.CoreEditor --path install="C:\VS"

使用 exportUsing export

此命令列命令是 15.9 中的新功能This command-line command is new in 15.9. 如需其詳細資訊,請參閱使用命令列參數安裝 Visual Studio 頁面。For more information about it, see the Use command-line parameters to install Visual Studio page.

  • 使用 export 可儲存來自安裝的選取項目:Using export to save the selection from an installation:
vs_enterprise.exe export --installPath "C:\VS" --config "C:\.vsconfig"
  • 使用 export 可從頭開始儲存自訂選取項目:Using export to save custom selection from scratch:
vs_enterprise.exe export --add Microsoft.VisualStudio.Workload.ManagedDesktop --includeRecommended --config "C:\.vsconfig"

使用 --configUsing --config

此命令列參數是 15.9 中的新功能This command-line parameter is new in 15.9. 如需其詳細資訊,請參閱使用命令列參數安裝 Visual Studio 頁面。For more information about it, see the Use command-line parameters to install Visual Studio page.

  • 使用 --config 可從先前儲存的安裝組態檔安裝工作負載和元件:Using --config to install the workloads and components from a previously saved installation configuration file:
vs_enterprise.exe --config "C:\.vsconfig" --installPath "C:\VS"
  • 使用 --config 可將工作負載和元件新增至現有的安裝:Using --config to add workloads and components to an existing installation:
vs_enterprise.exe modify --installPath "C:\VS" --config "C:\.vsconfig"

取得支援Get support

有時可能會發生一些問題。Sometimes, things can go wrong. 若安裝 Visual Studio 失敗,請參閱針對 Visual Studio 2017 安裝和升級問題進行疑難排解中的逐步說明。If your Visual Studio installation fails, see Troubleshooting Visual Studio 2017 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