Command-line parameter examples for installation - Visual Studio (Windows) (original) (raw)

To illustrate how to use command-line parameters to install Visual Studio, here are several examples that you can customize to match your needs.

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 (~ 1MB) file that initiates the download process. If you're using a different edition, substitute the appropriate bootstrapper name.

All commands require administrative elevation, and a User Account Control prompt will be displayed if the process isn't started from an elevated prompt.

You can use the ^ character at the end of a command line to concatenate multiple lines into a single command. Alternatively, you can place these lines together onto a single row. In PowerShell, the equivalent is the backtick (`) character.

To execute commands in a non-interactive manner, you can use--passive or --quiet. For more information on these parameters, see the commands and command-line paremeters page.

For lists of the workloads and components that you can install by using the command line, see the Visual Studio workload and component IDs page.

Install using --installPath and --add alongside the bootstrapper

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

Update

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

Alternatively, you can also update your Visual Studio instance in one step by using the installer on the client. Note that you can't initiate the installer programmatically from the same directory that the installer resides in.

"C:\Program Files (x86)\Microsoft Visual Studio\Installer\setup.exe" update --passive --norestart --installPath "C:\installPathVS"  

Standard users, if they've been granted appropriate permissions, can programmatically execute the update command using the installer, but they aren't allowed to use the --passive or --quiet switch.

Using --wait

start /wait vs_professional.exe --installPath "C:\VS" --passive --wait > nul  
echo %errorlevel%  

The following command is an example of using --wait with the PowerShell script command Start-Process:

$process = Start-Process -FilePath vs_enterprise.exe -ArgumentList "--installPath", "C:\VS", "--passive", "--wait" -Wait -PassThru  
Write-Output $process.ExitCode  

or

  $startInfo = New-Object System.Diagnostics.ProcessStartInfo  
  $startInfo.FileName = "vs_enterprise.exe"  
  $startInfo.Arguments = "--all --quiet --wait"  
  $process = New-Object System.Diagnostics.Process  
  <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mi>r</mi><mi>o</mi><mi>c</mi><mi>e</mi><mi>s</mi><mi>s</mi><mi mathvariant="normal">.</mi><mi>S</mi><mi>t</mi><mi>a</mi><mi>r</mi><mi>t</mi><mi>I</mi><mi>n</mi><mi>f</mi><mi>o</mi><mo>=</mo></mrow><annotation encoding="application/x-tex">process.StartInfo = </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">p</span><span class="mord mathnormal">rocess</span><span class="mord">.</span><span class="mord mathnormal">St</span><span class="mord mathnormal">a</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="mord mathnormal">n</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">o</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span></span></span>startInfo  
  $process.Start()  
  $process.WaitForExit()  

Using --layout to create a network layout or a local cache

vs_professional.exe --layout "C:\VS" ^  
--lang en-US ^  
--add Microsoft.VisualStudio.Workload.CoreEditor ^  

Using --all to acquire the entire product

vs_enterprise.exe --all  

Using --includeRecommended

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

Using --channelURI

Using the latest installer, it's possible to configure where Visual Studio looks for updates. The --channelUri is otherwise known as the update channel or the source location of updates. The following table gives example values for channelId and channelUri and what they mean.

Channel Name --channelUri --channelId
Visual Studio 2022 Current channel https://aka.ms/vs/17/release/channel VisualStudio.17.Release
Visual Studio 2022 17.0 LTSC channel https://aka.ms/vs/17/release.LTSC.17.0/channel VisualStudio.17.Release.LTSC.17.0
Visual Studio 2022 Preview channel https://aka.ms/vs/17/pre/channel VisualStudio.17.Preview
Visual Studio 2019 Release channel https://aka.ms/vs/16/release/channel VisualStudio.16.Release
Visual Studio 2017 Release channel https://aka.ms/vs/15/release/channel VisualStudio.15.Release
Custom layout - Private Channel \\layoutserver\share\path\channelmanifest.json VisualStudio.17.Release (or whatever the layout was based on)

If you choose to use a custom layout as the update channel, then be aware of the following guidelines:

Using --remove

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

You can't use --remove in the same command as --layout. In other words, it's not possible to remove components from a layout.

Using --removeOos

Using the latest installer, you can modify an installation and remove all components that have transitioned to an out-of-support state from the default installed Visual Studio instance. This example uses the installer already installed on the client machine to configure the removeOos setting. Standard users, if they've been granted appropriate permissions, can programmatically execute the modify command using the installer, but they aren't allowed to use the --passive or --quiet switch. You can't initiate the installer programmatically from the same directory that the installer resides in.

 "C:\Program Files (x86)\Microsoft Visual studio\Installer\setup.exe" modify ^
 --installPath "C:\Program Files\Microsoft Visual Studio\2022\Enterprise" ^
 --removeOos true ^
 --passive
"C:\Program Files (x86)\Microsoft Visual studio\Installer\setup.exe" modify ^  
--channelURI https://aka.ms/vs/17/release.LTSC.17.0/channel ^  
--productID Microsoft.VisualStudio.Product.Enterprise ^  
--newChannelURI \\layoutserver\share\path\channelmanifest.json ^  
--removeOos true ^  
--quiet  

Using --path

All of these examples assume you're installing a new product using a bootstrapper.

Using export

"C:\Program Files (x86)\Microsoft Visual Studio\Installer\setup.exe" export --installPath "C:\VS" --config "C:\my.vsconfig"  
"C:\Program Files (x86)\Microsoft Visual Studio\Installer\setup.exe" export --channelId VisualStudio.17.Release --productId Microsoft.VisualStudio.Product.Enterprise --add Microsoft.VisualStudio.Workload.ManagedDesktop --includeRecommended --config "C:\my.vsconfig"  

Using --config

vs_enterprise.exe --config "C:\my.vsconfig" --installPath "C:\VS"  
"C:\Program Files (x86)\Microsoft Visual Studio\Installer\setup.exe" modify --installPath "C:\VS" --config "C:\my.vsconfig"  
vs_enterprise.exe --layout C:\layout --config "C:\my.vsconfig"  

Using winget

Use the Windows Package Manager "winget" tool to programmatically install or update Visual Studio on your machines along with other packages managed by winget. To customize the installation and specify other workloads and components, you can use winget's --override switch alongside winget's install command, and pass in an exported vsconfig file like this:

winget install --id Microsoft.VisualStudio.2022.Community --override "--passive --config C:\my.vsconfig"

You can also use winget configure and pass in a .yaml file to modify an existing Visual Studio installation. This approach uses the Visual Studio PowerShell DSC provider that is documented here.

Support or troubleshooting

Sometimes, things can go wrong. If your Visual Studio installation fails, see Troubleshoot Visual Studio installation and upgrade issues for step-by-step guidance.

Here are a few more support options: