InstallVisualStudio.ps1 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <#
  2. .SYNOPSIS
  3. Installs or updates Visual Studio on a local developer machine.
  4. .DESCRIPTION
  5. This installs Visual Studio along with all the workloads required to contribute to this repository.
  6. .PARAMETER Edition
  7. Must be one of these values:
  8. Community
  9. Professional
  10. Enterprise
  11. Selects which 'offering' of Visual Studio to install.
  12. .PARAMETER InstallPath
  13. The location of Visual Studio
  14. .PARAMETER Passive
  15. Run the installer without requiring interaction.
  16. .LINK
  17. https://visualstudio.com
  18. https://github.com/aspnet/AspNetCore/blob/master/docs/BuildFromSource.md
  19. .EXAMPLE
  20. To install VS 2017 Community, run
  21. InstallVisualStudio.ps1 -Edition Community
  22. #>
  23. [CmdletBinding(DefaultParameterSetName = 'Default')]
  24. param(
  25. [ValidateSet('Community', 'Professional', 'Enterprise')]
  26. [string]$Edition,
  27. [string]$InstallPath,
  28. [switch]$Passive
  29. )
  30. if (-not $Edition) {
  31. Write-Host "You must specify a value for the -Edition parameter which selects the kind of Visual Studio to install." -f Red
  32. Write-Host "Run ``Get-Help $PSCommandPath`` for more details." -f Red
  33. Write-Host ""
  34. Write-Host "Example: ./InstallVisualStudio -Edition Community" -f Red
  35. Write-Host ""
  36. exit 1
  37. }
  38. $ErrorActionPreference = 'Stop'
  39. Set-StrictMode -Version 1
  40. $intermedateDir = "$PSScriptRoot\obj"
  41. mkdir $intermedateDir -ErrorAction Ignore | Out-Null
  42. $bootstrapper = "$intermedateDir\vsinstaller.exe"
  43. Invoke-WebRequest -Uri "https://aka.ms/vs/15/release/vs_$($Edition.ToLowerInvariant()).exe" -OutFile $bootstrapper
  44. if (-not $InstallPath) {
  45. $InstallPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017\$Edition"
  46. }
  47. # no backslashes - this breaks the installer
  48. $InstallPath = $InstallPath.TrimEnd('\')
  49. [string[]] $arguments = @()
  50. if (Test-path $InstallPath) {
  51. $arguments += 'modify'
  52. }
  53. $arguments += `
  54. '--productId', "Microsoft.VisualStudio.Product.$Edition", `
  55. '--installPath', "`"$InstallPath`"", `
  56. '--in', "$PSScriptRoot\vs.json", `
  57. '--norestart'
  58. if ($Passive) {
  59. $arguments += '--passive'
  60. }
  61. Write-Host ""
  62. Write-Host "Installing Visual Studio 2017 $Edition" -f Magenta
  63. Write-Host ""
  64. Write-Host "Running '$bootstrapper $arguments'"
  65. & $bootstrapper @arguments